{"record":{"id":"51a66251eec14e79","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-51a662","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"lib/subutil/src/main/java/com/blankj/subutil/util/DangerousUtils.java","lineNumber":37,"sourceCode":"import java.util.List;\n\nimport androidx.annotation.RequiresPermission;\n\nimport static android.Manifest.permission.MODIFY_PHONE_STATE;\nimport static android.Manifest.permission.SEND_SMS;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2019/06/29\n *     desc  :\n * </pre>\n */\npublic class DangerousUtils {\n\n    private DangerousUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    ///////////////////////////////////////////////////////////////////////////\n    // AppUtils\n    ///////////////////////////////////////////////////////////////////////////\n\n    /**\n     * Install the app silently.\n     * <p>Without root permission must hold\n     * {@code android:sharedUserId=\"android.uid.shell\"} and\n     * {@code <uses-permission android:name=\"android.permission.INSTALL_PACKAGES\" />}</p>\n     *\n     * @param filePath The path of file.\n     * @return {@code true}: success<br>{@code false}: fail\n     */\n    public static boolean installAppSilent(final String filePath) {\n        return installAppSilent(getFileByPath(filePath), null);\n    }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/subutil/src/main/java/com/blankj/subutil/util/DangerousUtils.java#L19-L55","documentation":"DangerousUtils is a utility class whose private constructor throws UnsupportedOperationException to block instantiation. All functionality is exposed as static methods; the class is not meant to hold instance state.","triggerScenarios":"Reflective instantiation (Constructor.newInstance) or unsafe object creation targeting DangerousUtils.","commonSituations":"DI/serialization frameworks or code generators that instantiate arbitrary classes; reflective test scaffolding that builds utility classes.","solutions":["Use the static methods directly, e.g. DangerousUtils.silentInstall(...); never hold an instance.","Configure reflective frameworks to skip final utility classes.","Remove reflection that constructs DangerousUtils."],"exampleFix":"// before\nDangerousUtils d = reflectiveNew(DangerousUtils.class); // throws\n\n// after\nDangerousUtils.installAppSilent(filePath, listener);","handlingStrategy":"validation","validationCode":"// DangerousUtils is static-only; never instantiate.\nDangerousUtils.installAppSilent(path, listener);","typeGuard":"private static boolean isStaticUtility(Class<?> c) {\n    return Modifier.isFinal(c.getModifiers()) && hasOnlyStaticMethods(c);\n}","tryCatchPattern":null,"preventionTips":["Use DangerousUtils via its static methods only.","Configure DI/serialization frameworks to skip utility classes.","Remove reflective newInstance calls targeting utilities."],"tags":["android","utility","instantiation","reflection"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}