{"record":{"id":"5fbc7f7ac1fd73d1","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-5fbc7f","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/RomUtils.java","lineNumber":61,"sourceCode":"    private static final String[] ROM_SONY      = {\"sony\"};\n    private static final String[] ROM_GIONEE    = {\"gionee\", \"amigo\"};\n    private static final String[] ROM_MOTOROLA  = {\"motorola\"};\n\n    private static final String VERSION_PROPERTY_HUAWEI  = \"ro.build.version.emui\";\n    private static final String VERSION_PROPERTY_VIVO    = \"ro.vivo.os.build.display.id\";\n    private static final String VERSION_PROPERTY_XIAOMI  = \"ro.build.version.incremental\";\n    private static final String VERSION_PROPERTY_OPPO    = \"ro.build.version.opporom\";\n    private static final String VERSION_PROPERTY_LEECO   = \"ro.letv.release.version\";\n    private static final String VERSION_PROPERTY_360     = \"ro.build.uiversion\";\n    private static final String VERSION_PROPERTY_ZTE     = \"ro.build.MiFavor_version\";\n    private static final String VERSION_PROPERTY_ONEPLUS = \"ro.rom.version\";\n    private static final String VERSION_PROPERTY_NUBIA   = \"ro.build.rom.id\";\n    private final static String UNKNOWN                  = \"unknown\";\n\n    private static RomInfo bean = null;\n\n    private RomUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Return whether the rom is made by huawei.\n     *\n     * @return {@code true}: yes<br>{@code false}: no\n     */\n    public static boolean isHuawei() {\n        return ROM_HUAWEI[0].equals(getRomInfo().name);\n    }\n\n    /**\n     * Return whether the rom is made by vivo.\n     *\n     * @return {@code true}: yes<br>{@code false}: no\n     */\n    public static boolean isVivo() {\n        return ROM_VIVO[0].equals(getRomInfo().name);","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/RomUtils.java#L43-L79","documentation":"RomUtils is a utility class providing static methods for detecting the device's Android ROM manufacturer (isHuawei, isXiaomi, isOppo, getRomInfo, etc.) by reading system properties. 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; instrumentation frameworks that instantiate all loaded classes.","solutions":["Use static methods: RomUtils.isHuawei(), RomUtils.getRomInfo(). Never call new RomUtils().","Exclude utility classes from DI scanning and serialization configs.","Mock static methods with mockito-inline for testing."],"exampleFix":"// before\nRomUtils ru = new RomUtils();\nboolean huawei = ru.isHuawei();\n\n// after\nboolean huawei = RomUtils.isHuawei();","handlingStrategy":"type-guard","validationCode":"// RomUtils is static-only\nboolean huawei = RomUtils.isHuawei();\nRomUtils.RomInfo info = RomUtils.getRomInfo();","typeGuard":"static boolean isStaticUtility(Class<?> c) {\n    return c.getSimpleName().endsWith(\"Utils\");\n}","tryCatchPattern":"try {\n    RomUtils.class.getDeclaredConstructor().setAccessible(true);\n    RomUtils.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 RomUtils.isHuawei(), getRomInfo(), etc. statically."],"tags":["java","android","utility-class","instantiation","rom"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}