{"record":{"id":"a83a985a12e8fc6f","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-a83a98","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/UriUtils.java","lineNumber":36,"sourceCode":"import java.io.IOException;\nimport java.io.InputStream;\nimport java.lang.reflect.Array;\nimport java.lang.reflect.Method;\n\nimport androidx.core.content.FileProvider;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2018/04/20\n *     desc  : utils about uri\n * </pre>\n */\npublic final class UriUtils {\n\n    private UriUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Resource to uri.\n     * <p>res2Uri([res type]/[res name]) -> res2Uri(drawable/icon), res2Uri(raw/icon)</p>\n     * <p>res2Uri([resource_id]) -> res2Uri(R.drawable.icon)</p>\n     *\n     * @param resPath The path of res.\n     * @return uri\n     */\n    public static Uri res2Uri(String resPath) {\n        return Uri.parse(\"android.resource://\" + Utils.getApp().getPackageName() + \"/\" + resPath);\n    }\n\n    /**\n     * File to uri.\n     *\n     * @param file The file.","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/UriUtils.java#L18-L54","documentation":"UriUtils is a final static-only utility for URI/resource-path conversions. Its private constructor throws UnsupportedOperationException to prevent instantiation. All public methods (res2Uri, etc.) are static.","triggerScenarios":"Reflective instantiation via UriUtils.class.getDeclaredConstructor().setAccessible(true).newInstance(), or transitively through Gson/Jackson deserialization, Mockito/PowerMock, Kotlin reflection, or a DI scan.","commonSituations":"JSON mapping a field to UriUtils; mock frameworks in tests; coverage probes; accidental construction after weakening access modifiers.","solutions":["Use static methods: UriUtils.res2Uri(resPath) instead of constructing the class.","Provide a Gson InstanceCreator / Jackson mixin returning a sentinel to avoid constructor invocation.","Use Mockito.mockStatic for mocking rather than constructing UriUtils.","Keep the class final with a private constructor."],"exampleFix":"// before\nUriUtils uu = new UriUtils();\n\n// after\nUri uri = UriUtils.res2Uri(\"drawable/icon\");","handlingStrategy":"validation","validationCode":"if (Modifier.isFinal(UriUtils.class.getModifiers())) {\n  throw new IllegalStateException(\"UriUtils is static-only.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call UriUtils.res2Uri(...) statically.","Register InstanceCreator/mixin for JSON fields.","Use Mockito.mockStatic for mocking.","Keep final + private constructor."],"tags":["android","utility-class","reflection","instantiation","uri"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}