{"record":{"id":"67ef41c3ba4472d2","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-67ef41","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java","lineNumber":35,"sourceCode":"import androidx.annotation.NonNull;\nimport androidx.annotation.Nullable;\n\nimport java.io.File;\nimport java.util.ArrayList;\nimport java.util.List;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2016/08/02\n *     desc  : utils about app\n * </pre>\n */\npublic final class AppUtils {\n\n    private AppUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Register the status of application changed listener.\n     *\n     * @param listener The status of application changed listener\n     */\n    public static void registerAppStatusChangedListener(@NonNull final Utils.OnAppStatusChangedListener listener) {\n        UtilsBridge.addOnAppStatusChangedListener(listener);\n    }\n\n    /**\n     * Unregister the status of application changed listener.\n     *\n     * @param listener The status of application changed listener\n     */\n    public static void unregisterAppStatusChangedListener(@NonNull final Utils.OnAppStatusChangedListener listener) {\n        UtilsBridge.removeOnAppStatusChangedListener(listener);","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java#L17-L53","documentation":"AppUtils (utilcode) is a final utility class whose private constructor throws UnsupportedOperationException. It exposes only static app-info helpers (install, version, status listeners); instances are forbidden.","triggerScenarios":"Reflective instantiation or unsafe allocation of AppUtils instead of calling its static methods.","commonSituations":"Reflection/DI/serialization frameworks that build arbitrary classes; tests that reflectively scaffold utilities.","solutions":["Use the static API, e.g. AppUtils.isAppDebug(), AppUtils.installApp(path); never instantiate.","Configure reflective frameworks to skip final utility classes.","Remove newInstance paths targeting AppUtils."],"exampleFix":"// before\nAppUtils a = reflectNew(AppUtils.class); // throws\n\n// after\nboolean debug = AppUtils.isAppDebug();","handlingStrategy":"validation","validationCode":"// AppUtils is static-only; never instantiate.\nboolean debug = AppUtils.isAppDebug();","typeGuard":"private static boolean isStaticUtility(Class<?> c) {\n    return Modifier.isFinal(c.getModifiers()) && hasOnlyStaticMethods(c);\n}","tryCatchPattern":null,"preventionTips":["Use AppUtils via its static methods only.","Configure reflective frameworks to skip final utility classes.","Remove newInstance paths targeting the class."],"tags":["android","utility","instantiation","reflection","app"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}