{"record":{"id":"2bed571e1ffa522a","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-2bed57","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/CloneUtils.java","lineNumber":16,"sourceCode":"package com.blankj.utilcode.util;\n\nimport java.lang.reflect.Type;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2018/01/30\n *     desc  : utils about clone\n * </pre>\n */\npublic final class CloneUtils {\n\n    private CloneUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Deep clone.\n     *\n     * @param data The data.\n     * @param type The type.\n     * @param <T>  The value type.\n     * @return The object of cloned.\n     */\n    public static <T> T deepClone(final T data, final Type type) {\n        try {\n            return UtilsBridge.fromJson(UtilsBridge.toJson(data), type);\n        } catch (Exception e) {\n            e.printStackTrace();\n            return null;\n        }\n    }","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/CloneUtils.java#L1-L34","documentation":"CloneUtils is a final utility class with static deep-clone helpers; its private constructor throws UnsupportedOperationException('u can't instantiate me...') to forbid construction. The throw is an intentional guard reachable only via reflection, because the class is final and the constructor is private.","triggerScenarios":"Reflectively invoking the private constructor (setAccessible(true) + newInstance()); coverage or generic reflection tooling that instantiates every class; frameworks that auto-construct helper classes.","commonSituations":"Code-coverage tools (JaCoCo/Cobertura) covering private constructors; blanket reflection tests across a package; DI/serialization frameworks attempting default construction.","solutions":["Call static methods directly (e.g., CloneUtils.deepClone(data, type)) and never instantiate.","Exclude the constructor from coverage or rely on the coverage helper.","If testing the guard, assert UnsupportedOperationException rather than trying to succeed.","Remove reflective newInstance() calls against CloneUtils.class."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Never instantiate; call static methods directly.\nT copy = CloneUtils.deepClone(data, type);","typeGuard":null,"tryCatchPattern":"try {\n    Constructor<CloneUtils> c = CloneUtils.class.getDeclaredConstructor();\n    c.setAccessible(true);\n    c.newInstance();\n} catch (UnsupportedOperationException | InvocationTargetException e) {\n    // expected: instantiation is forbidden by design\n}","preventionTips":["Call CloneUtils static methods directly; never reflectively instantiate it.","Exclude private constructors from coverage tooling that auto-instantiates.","For guard tests, assert UnsupportedOperationException instead of trying to succeed."],"tags":["utility-class","private-constructor","reflection","cloneutils","android","java"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}