{"record":{"id":"80aec0159bf3d191","repo":"JessYanCoding/AndroidAutoSize","slug":"you-can-t-instantiate-me-80aec0","errorCode":null,"errorMessage":"you can't instantiate me!","messagePattern":"you can't instantiate me!","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"autosize/src/main/java/me/jessyan/autosize/utils/AutoSizeLog.java","lineNumber":32,"sourceCode":" * limitations under the License.\n */\npackage me.jessyan.autosize.utils;\n\nimport android.util.Log;\n\n/**\n * ================================================\n * Created by JessYan on 2018/8/8 18:48\n * <a href=\"mailto:jess.yan.effort@gmail.com\">Contact me</a>\n * <a href=\"https://github.com/JessYanCoding\">Follow me</a>\n * ================================================\n */\npublic class AutoSizeLog {\n    private static final String TAG = \"AndroidAutoSize\";\n    private static boolean debug;\n\n    private AutoSizeLog() {\n        throw new IllegalStateException(\"you can't instantiate me!\");\n    }\n\n    public static boolean isDebug() {\n        return debug;\n    }\n\n    public static void setDebug(boolean debug) {\n        AutoSizeLog.debug = debug;\n    }\n\n    public static void d(String message) {\n        if (debug) {\n            Log.d(TAG, message);\n        }\n    }\n\n    public static void w(String message) {\n        if (debug) {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/JessYanCoding/AndroidAutoSize/blob/e402ecdd998ea07549513ac08c12e9f097f3b48c/autosize/src/main/java/me/jessyan/autosize/utils/AutoSizeLog.java#L14-L50","documentation":"This is a deliberate sentinel guard, not a runtime failure of library code. AutoSizeLog is a static-only utility class (all members static), so its constructor is private; any attempt to instantiate it via `new AutoSizeLog()` (or via reflection, if setAccessible bypasses privacy) throws this IllegalStateException immediately. The input at fault is the instantiation attempt itself; correct usage is to call the static methods (e.g. AutoSizeLog.d/w/e) directly.","triggerScenarios":"Calling new AutoSizeLog() or letting a framework instantiate it.","commonSituations":"Reflection-based instantiation in tests or DI containers; developers treating the logging helper as an injectable logger object.","solutions":["Use the static methods, e.g. AutoSizeLog.debug(...), without creating an instance","Remove the instantiation code","Exclude static utility classes from auto-instantiation in DI/codegen tooling"],"exampleFix":"// before\nAutoSizeLog log = new AutoSizeLog();\n// after\nAutoSizeLog.debug(TAG, \"adaptation done\");","handlingStrategy":"try-catch","validationCode":"if (Modifier.isPrivate(AutoSizeLog.class.getDeclaredConstructor().getModifiers())) { /* logging helper: use statics */ }","typeGuard":"boolean isUtilityClass(Class<?> c) { return Modifier.isPrivate(c.getDeclaredConstructors()[0].getModifiers()); }","tryCatchPattern":"try { new AutoSizeLog(); } catch (IllegalStateException e) { /* expected: use AutoSizeLog.debug/warn/error statically */ }","preventionTips":["Use AutoSizeLog statically with your own TAG","Don't wrap AutoSizeLog in an instance-based logger that constructs it"],"tags":["java","static-class","logging"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"e402ecdd998ea07549513ac08c12e9f097f3b48c","analyzedAt":"2026-09-07T15:05:42.094Z","contentChangedAt":"2026-09-07T15:05:42.094Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}