{"record":{"id":"d9144ddb54b2c97d","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-d9144d","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java","lineNumber":27,"sourceCode":"import java.util.List;\n\nimport androidx.annotation.NonNull;\nimport androidx.annotation.Nullable;\n\n/**\n * <pre>\n *     author: blankj\n *     blog  : http://blankj.com\n *     time  : 2019/08/10\n *     desc  : utils about array\n * </pre>\n */\npublic class ArrayUtils {\n\n    public static final int INDEX_NOT_FOUND = -1;\n\n    private ArrayUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Returns a new array only of those given elements.\n     *\n     * @param array The array.\n     * @return a new array only of those given elements.\n     */\n    @NonNull\n    public static <T> T[] newArray(T... array) {\n        return array;\n    }\n\n    @NonNull\n    public static long[] newLongArray(long... array) {\n        return array;\n    }\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java#L9-L45","documentation":"ArrayUtils is a utility class (non-final) whose private constructor throws UnsupportedOperationException. It exposes static array helpers plus the INDEX_NOT_FOUND constant; instances are intentionally forbidden.","triggerScenarios":"Reflective instantiation or unsafe allocation of ArrayUtils instead of calling its static methods; subclassing with a public constructor is also unusual since the base constructor throws.","commonSituations":"Reflection/DI/serialization frameworks that build arbitrary classes; tests that reflectively scaffold utilities.","solutions":["Use the static API, e.g. ArrayUtils.newArray(...), ArrayUtils.add(...), ArrayUtils.indexOf(...); never instantiate.","Configure reflective frameworks to skip utility classes.","Remove newInstance paths targeting ArrayUtils."],"exampleFix":"// before\nArrayUtils a = reflectNew(ArrayUtils.class); // throws\n\n// after\nString[] arr = ArrayUtils.newArray(\"a\", \"b\");","handlingStrategy":"validation","validationCode":"// ArrayUtils is static-only; never instantiate.\nString[] arr = ArrayUtils.newArray(\"a\", \"b\");","typeGuard":"private static boolean isStaticUtility(Class<?> c) {\n    return hasOnlyStaticMethods(c);\n}","tryCatchPattern":null,"preventionTips":["Use ArrayUtils via its static methods only.","Configure reflective frameworks to skip utility classes.","Remove reflective newInstance calls targeting utilities."],"tags":["android","utility","instantiation","reflection","array"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}