{"record":{"id":"7165150840b66816","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-716515","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/utildebug-no-op/src/main/java/com/blankj/utildebug/DebugUtils.java","lineNumber":18,"sourceCode":"package com.blankj.utildebug;\n\nimport com.blankj.utildebug.debug.IDebug;\n\nimport java.util.List;\n\n/**\n * <pre>\n *     author: blankj\n *     blog  : http://blankj.com\n *     time  : 2019/08/28\n *     desc  : utils about debug\n * </pre>\n */\npublic class DebugUtils {\n\n    private DebugUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    public static void setIconId(final int icon) {\n    }\n\n    public static void addDebugs(final List<IDebug> debugs) {\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utildebug-no-op/src/main/java/com/blankj/utildebug/DebugUtils.java#L1-L27","documentation":"DebugUtils in the utildebug-no-op module is a no-op stub used in release builds to strip debug tooling at compile time. Its private constructor throws UnsupportedOperationException to prevent instantiation. All public methods (setIconId, addDebugs) are empty no-ops; the class exists only as a static API surface.","triggerScenarios":"Reflective instantiation via DebugUtils.class.getDeclaredConstructor().setAccessible(true).newInstance(), or transitively through Gson/Jackson deserialization, Mockito/PowerMock, Kotlin reflection, or a DI scan in a release-flavor build that resolves the no-op variant.","commonSituations":"Release builds swapping in the no-op artifact; serialization frameworks binding a field to DebugUtils; mock frameworks; coverage tooling; accidental construction after weakening modifiers.","solutions":["Call the (no-op) static methods: DebugUtils.setIconId(res) instead of constructing.","Provide a Gson InstanceCreator / Jackson mixin returning a sentinel so the constructor is not invoked.","Use Mockito.mockStatic for mocking rather than constructing DebugUtils.","Keep the class constructor private; remember this flavor intentionally has empty bodies."],"exampleFix":"// before\nDebugUtils du = new DebugUtils();\n\n// after\nDebugUtils.setIconId(R.drawable.ic_debug);","handlingStrategy":"validation","validationCode":"if (Modifier.isFinal(DebugUtils.class.getModifiers())) {\n  throw new IllegalStateException(\"DebugUtils (no-op) is static-only.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call DebugUtils.setIconId(...)/addDebugds(...) statically.","Remember the no-op flavor has empty bodies by design for release.","Register InstanceCreator/mixin for JSON fields.","Use Mockito.mockStatic for mocking."],"tags":["android","utility-class","reflection","instantiation","debug","noop"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}