{"record":{"id":"9f58f45a71f5bee8","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-9f58f4","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/CleanUtils.java","lineNumber":23,"sourceCode":"import android.os.Build;\nimport android.os.Environment;\n\nimport java.io.File;\n\nimport androidx.annotation.RequiresApi;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2016/09/27\n *     desc  : utils about clean\n * </pre>\n */\npublic final class CleanUtils {\n\n    private CleanUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Clean the internal cache.\n     * <p>directory: /data/data/package/cache</p>\n     *\n     * @return {@code true}: success<br>{@code false}: fail\n     */\n    public static boolean cleanInternalCache() {\n        return UtilsBridge.deleteAllInDir(Utils.getApp().getCacheDir());\n    }\n\n    /**\n     * Clean the internal files.\n     * <p>directory: /data/data/package/files</p>\n     *\n     * @return {@code true}: success<br>{@code false}: fail\n     */","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/CleanUtils.java#L5-L41","documentation":"CleanUtils is a final utility class with only static cleanup helpers; its private constructor throws UnsupportedOperationException('u can't instantiate me...') to forbid construction. The throw is an intentional guard reachable only via reflection, since 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 classes.","commonSituations":"Code-coverage tools (JaCoCo/Cobertura) covering private constructors; blanket reflection tests that instantiate all classes in a package; DI/serialization frameworks attempting no-arg construction.","solutions":["Call static methods directly (e.g., CleanUtils.cleanInternalCache()) and never instantiate.","Exclude the constructor from coverage requirements or use the coverage helper.","If testing the guard, assert UnsupportedOperationException is thrown rather than trying to succeed.","Remove reflective newInstance() calls against CleanUtils.class."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Never instantiate; call static methods directly.\nboolean ok = CleanUtils.cleanInternalCache();","typeGuard":null,"tryCatchPattern":"try {\n    Constructor<CleanUtils> c = CleanUtils.class.getDeclaredConstructor();\n    c.setAccessible(true);\n    c.newInstance();\n} catch (UnsupportedOperationException | InvocationTargetException e) {\n    // expected: instantiation is forbidden by design\n}","preventionTips":["Call CleanUtils 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","cleanutils","android","java"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}