{"record":{"id":"c96602d09f7099de","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-c96602","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/CloseUtils.java","lineNumber":17,"sourceCode":"package com.blankj.utilcode.util;\n\nimport java.io.Closeable;\nimport java.io.IOException;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2016/10/09\n *     desc  : utils about close\n * </pre>\n */\npublic final class CloseUtils {\n\n    private CloseUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Close the io stream.\n     *\n     * @param closeables The closeables.\n     */\n    public static void closeIO(final Closeable... closeables) {\n        if (closeables == null) return;\n        for (Closeable closeable : closeables) {\n            if (closeable != null) {\n                try {\n                    closeable.close();\n                } catch (IOException e) {\n                    e.printStackTrace();\n                }\n            }\n        }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/CloseUtils.java#L1-L35","documentation":"CloseUtils is a final utility class with static IO-close 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 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., CloseUtils.closeIO(stream)) 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 CloseUtils.class."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Never instantiate; call static methods directly.\nCloseUtils.closeIO(stream);","typeGuard":null,"tryCatchPattern":"try {\n    Constructor<CloseUtils> c = CloseUtils.class.getDeclaredConstructor();\n    c.setAccessible(true);\n    c.newInstance();\n} catch (UnsupportedOperationException | InvocationTargetException e) {\n    // expected: instantiation is forbidden by design\n}","preventionTips":["Call CloseUtils 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","closeutils","android","java"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}