{"record":{"id":"fd8f40f99bd3910b","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-fd8f40","errorCode":null,"errorMessage":"u can't instantiate me...","messagePattern":"u can't instantiate me\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java","lineNumber":35,"sourceCode":"import androidx.annotation.NonNull;\nimport androidx.annotation.Nullable;\nimport androidx.annotation.RequiresPermission;\nimport androidx.core.content.FileProvider;\n\nimport static android.Manifest.permission.CALL_PHONE;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2016/09/23\n *     desc  : utils about intent\n * </pre>\n */\npublic final class IntentUtils {\n\n    private IntentUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Return whether the intent is available.\n     *\n     * @param intent The intent.\n     * @return {@code true}: yes<br>{@code false}: no\n     */\n    public static boolean isIntentAvailable(final Intent intent) {\n        return Utils.getApp()\n                .getPackageManager()\n                .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)\n                .size() > 0;\n    }\n\n    /**\n     * Return the intent of install app.\n     * <p>Target APIs greater than 25 must hold","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/IntentUtils.java#L17-L53","documentation":"IntentUtils is a final utility class whose private constructor throws UnsupportedOperationException(\"u can't instantiate me...\"). All intent helpers (isIntentAvailable, launchApp, shareText, openUrl, getInstallAppIntent, etc.) are static; the constructor exists only to block instantiation, consistent with the library-wide *Utils convention.","triggerScenarios":"Reflective construction via getDeclaredConstructor().newInstance() with setAccessible, or a framework that new-ups classes by Class reference. A direct `new IntentUtils()` fails to compile because the constructor is private.","commonSituations":"Coverage tooling that instantiates all classes; DI containers scanning packages; a developer who assumes instance methods; reflective test harnesses that exercise all constructors.","solutions":["Use the static API directly: IntentUtils.isIntentAvailable(intent), IntentUtils.launchApp(pkgName), IntentUtils.openUrl(url), etc.","Add IntentUtils to the exclusion list of any tool that reflectively instantiates classes.","For a contract test, expect UnsupportedOperationException from the reflected constructor."],"exampleFix":"// before (reflection)\nIntentUtils iu = IntentUtils.class.getDeclaredConstructor().newInstance();\n\n// after\nif (IntentUtils.isIntentAvailable(intent)) startActivity(intent);","handlingStrategy":"validation","validationCode":"// Never construct IntentUtils; it is static-only.\nif (clazz == IntentUtils.class || Modifier.isFinal(clazz.getModifiers())) {\n    // skip instantiation; use IntentUtils.xxx() statically\n}","typeGuard":"if (clazz.getName().endsWith(\"Utils\") && Modifier.isFinal(clazz.getModifiers())) {\n    // static-only; do not newInstance()\n}","tryCatchPattern":"try {\n    Constructor<?> c = IntentUtils.class.getDeclaredConstructor();\n    c.setAccessible(true);\n    c.newInstance();\n} catch (UnsupportedOperationException e) {\n    // expected; use IntentUtils.xxx() instead\n}","preventionTips":["IntentUtils is static-only — never instantiate via `new` or reflection.","Exclude final 'Utils' classes from coverage/DI/mutation tools that construct everything.","Call IntentUtils.isIntentAvailable()/launchApp()/openUrl() statically."],"tags":["utility-class","instantiation","design-pattern","reflection","intent"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}