{"record":{"id":"06c63c4a09ffd9ca","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-06c63c","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/PathUtils.java","lineNumber":22,"sourceCode":"import android.os.Environment;\nimport android.text.TextUtils;\n\nimport java.io.File;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2018/04/15\n *     desc  : utils about path\n * </pre>\n */\npublic final class PathUtils {\n\n    private static final char SEP = File.separatorChar;\n\n    private PathUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Join the path.\n     *\n     * @param parent The parent of path.\n     * @param child  The child path.\n     * @return the path\n     */\n    public static String join(String parent, String child) {\n        if (TextUtils.isEmpty(child)) return parent;\n        if (parent == null) {\n            parent = \"\";\n        }\n        int len = parent.length();\n        String legalSegment = getLegalSegment(child);\n        String newPath;\n        if (len == 0) {","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/PathUtils.java#L4-L40","documentation":"PathUtils is a final utility class providing static methods for Android filesystem path operations (join, getRootPath, getDataPath, getExternalStoragePath, 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: PathUtils.join(parent, child), PathUtils.getRootPath(). Never call new PathUtils().","Exclude utility classes from DI scanning and serialization configs.","Mock static methods with mockito-inline for testing."],"exampleFix":"// before\nPathUtils pu = new PathUtils();\nString path = pu.join(\"/data\", \"files\");\n\n// after\nString path = PathUtils.join(\"/data\", \"files\");","handlingStrategy":"type-guard","validationCode":"// PathUtils is static-only\nString path = PathUtils.join(\"/data\", \"files\");\nString root = PathUtils.getRootPath();","typeGuard":"static boolean isStaticUtility(Class<?> c) {\n    return Modifier.isFinal(c.getModifiers()) && c.getSimpleName().endsWith(\"Utils\");\n}","tryCatchPattern":"try {\n    PathUtils.class.getDeclaredConstructor().setAccessible(true);\n    PathUtils.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 PathUtils.join(), PathUtils.getRootPath(), etc. statically."],"tags":["java","android","utility-class","instantiation","path"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}