{"record":{"id":"c87017e5b3ef4e62","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-c87017","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/LogUtils.java","lineNumber":109,"sourceCode":"            \"┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄\";\n    private static final String TOP_BORDER     = TOP_CORNER + SIDE_DIVIDER + SIDE_DIVIDER;\n    private static final String MIDDLE_BORDER  = MIDDLE_CORNER + MIDDLE_DIVIDER + MIDDLE_DIVIDER;\n    private static final String BOTTOM_BORDER  = BOTTOM_CORNER + SIDE_DIVIDER + SIDE_DIVIDER;\n    private static final int    MAX_LEN        = 1100;// fit for Chinese character\n    private static final String NOTHING        = \"log nothing\";\n    private static final String NULL           = \"null\";\n    private static final String ARGS           = \"args\";\n    private static final String PLACEHOLDER    = \" \";\n    private static final Config CONFIG         = new Config();\n\n    private static SimpleDateFormat simpleDateFormat;\n\n    private static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();\n\n    private static final SimpleArrayMap<Class, IFormatter> I_FORMATTER_MAP = new SimpleArrayMap<>();\n\n    private LogUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    public static Config getConfig() {\n        return CONFIG;\n    }\n\n    public static void v(final Object... contents) {\n        log(V, CONFIG.getGlobalTag(), contents);\n    }\n\n    public static void vTag(final String tag, final Object... contents) {\n        log(V, tag, contents);\n    }\n\n    public static void d(final Object... contents) {\n        log(D, CONFIG.getGlobalTag(), contents);\n    }\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/LogUtils.java#L91-L127","documentation":"LogUtils is a final utility class providing configurable logging with tag formatting, type-aware object serialization, and background thread execution. Its private constructor throws UnsupportedOperationException to enforce static-only access. The class holds a static Config instance and an ExecutorService for async logging.","triggerScenarios":"Reflective instantiation by DI/mock/serialization frameworks, or direct reflection calls (Class.getDeclaredConstructor().newInstance()). The constructor itself is private so normal compilation prevents direct new LogUtils().","commonSituations":"Mockito mock creation targeting LogUtils; Gson/Jackson deserialization with the class as a target type; a DI component scanner that traverses utility packages; ProGuard keep rules that preserve the class for reflective construction.","solutions":["Use static methods: LogUtils.v(), LogUtils.d(), LogUtils.i(), LogUtils.w(), LogUtils.e(). Use LogUtils.getConfig() for configuration.","Exclude LogUtils from DI scanning, serialization targets, and keep-rule instantiation.","For testing, mock static methods with mockito-inline instead of instantiating."],"exampleFix":"// before\nLogUtils logger = new LogUtils();\nlogger.d(\"message\");\n\n// after\nLogUtils.d(\"message\");","handlingStrategy":"type-guard","validationCode":"// LogUtils is static-only — never instantiate\n// Configure LogUtils via LogUtils.getConfig() at app startup\nLogUtils.getConfig().setGlobalTag(\"MyApp\").setLogSwitch(BuildConfig.DEBUG);","typeGuard":"static boolean isLogUtils(Class<?> c) {\n    return c == LogUtils.class;\n}\n// If true, only use static methods — never reflectively instantiate","tryCatchPattern":"try {\n    LogUtils.class.getDeclaredConstructor().setAccessible(true);\n    LogUtils.class.getDeclaredConstructor().newInstance();\n} catch (UnsupportedOperationException e) {\n    // Use LogUtils.d(), LogUtils.v(), etc. statically\n}","preventionTips":["Never instantiate LogUtils — configure via LogUtils.getConfig().","Exclude LogUtils from DI scanning and serialization targets.","Mock static log methods with mockito-inline for testing."],"tags":["java","android","utility-class","instantiation","logging"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}