{"record":{"id":"a707b8e0bfe17bc4","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-a707b8","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/SDCardUtils.java","lineNumber":26,"sourceCode":"\nimport java.lang.reflect.Array;\nimport java.lang.reflect.InvocationTargetException;\nimport java.lang.reflect.Method;\nimport java.util.ArrayList;\nimport java.util.List;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2016/08/11\n *     desc  : utils about sdcard\n * </pre>\n */\npublic final class SDCardUtils {\n\n    private SDCardUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Return whether sdcard is enabled by environment.\n     *\n     * @return {@code true}: enabled<br>{@code false}: disabled\n     */\n    public static boolean isSDCardEnableByEnvironment() {\n        return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());\n    }\n\n    /**\n     * Return the path of sdcard by environment.\n     *\n     * @return the path of sdcard by environment\n     */\n    public static String getSDCardPathByEnvironment() {\n        if (isSDCardEnableByEnvironment()) {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/SDCardUtils.java#L8-L44","documentation":"SDCardUtils is a final utility class providing static methods for SD card detection and path retrieval (isSDCardEnableByEnvironment, getSDCardPath, getInternalStoragePath, etc.). Its private constructor throws UnsupportedOperationException to enforce static-only access.","triggerScenarios":"Direct or reflective instantiation by DI frameworks, mocking libraries, serialization frameworks, or manual reflection.","commonSituations":"DI component scanning traverses the utility package; a test framework instantiates all classes for coverage; a serialization library targets the class.","solutions":["Use static methods: SDCardUtils.isSDCardEnableByEnvironment(), SDCardUtils.getSDCardPath(). Never call new SDCardUtils().","Exclude utility classes from DI scanning and serialization configs.","Mock static methods with mockito-inline for testing."],"exampleFix":"// before\nSDCardUtils sdu = new SDCardUtils();\nboolean enabled = sdu.isSDCardEnableByEnvironment();\n\n// after\nboolean enabled = SDCardUtils.isSDCardEnableByEnvironment();","handlingStrategy":"type-guard","validationCode":"// SDCardUtils is static-only\nboolean enabled = SDCardUtils.isSDCardEnableByEnvironment();\nString sdPath = SDCardUtils.getSDCardPath();","typeGuard":"static boolean isStaticUtility(Class<?> c) {\n    return Modifier.isFinal(c.getModifiers()) && c.getSimpleName().endsWith(\"Utils\");\n}","tryCatchPattern":"try {\n    SDCardUtils.class.getDeclaredConstructor().setAccessible(true);\n    SDCardUtils.class.getDeclaredConstructor().newInstance();\n} catch (UnsupportedOperationException e) {\n    // Use static methods\n}","preventionTips":["Never instantiate classes ending in 'Utils'.","Exclude util packages from DI and serialization scanning.","Use SDCardUtils.isSDCardEnableByEnvironment(), getSDCardPath(), etc. statically."],"tags":["java","android","utility-class","instantiation","sdcard"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}