{"record":{"id":"1d00fc9320b61a6d","repo":"Blankj/AndroidUtilCode","slug":"u-can-t-instantiate-me-1d00fc","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/StringUtils.java","lineNumber":21,"sourceCode":"import android.content.res.Resources;\nimport androidx.annotation.ArrayRes;\nimport androidx.annotation.Nullable;\nimport androidx.annotation.StringRes;\n\nimport java.util.IllegalFormatException;\n\n/**\n * <pre>\n *     author: Blankj\n *     blog  : http://blankj.com\n *     time  : 2016/08/16\n *     desc  : utils about string\n * </pre>\n */\npublic final class StringUtils {\n\n    private StringUtils() {\n        throw new UnsupportedOperationException(\"u can't instantiate me...\");\n    }\n\n    /**\n     * Return whether the string is null or 0-length.\n     *\n     * @param s The string.\n     * @return {@code true}: yes<br> {@code false}: no\n     */\n    public static boolean isEmpty(final CharSequence s) {\n        return s == null || s.length() == 0;\n    }\n\n    /**\n     * Return whether the string is null or whitespace.\n     *\n     * @param s The string.\n     * @return {@code true}: yes<br> {@code false}: no\n     */","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/StringUtils.java#L3-L39","documentation":"StringUtils is a final static-only utility for string checks and manipulation. Its private constructor throws UnsupportedOperationException to prevent instantiation. All public methods are static, so construction is a contract violation.","triggerScenarios":"Reflective instantiation (StringUtils.class.getDeclaredConstructor().setAccessible(true).newInstance()) or transitive construction through Gson/Jackson deserialization, Mockito/PowerMock, Kotlin reflection, or a DI classpath scan.","commonSituations":"JSON libraries binding a field to StringUtils; test frameworks mocking utility classes; coverage probes; accidental instantiation after weakening access modifiers.","solutions":["Use static methods: StringUtils.isEmpty(s) instead of constructing the class.","Provide a Gson InstanceCreator / Jackson mixin returning a sentinel to avoid constructor invocation.","Mock static methods with Mockito.mockStatic instead of constructing StringUtils.","Keep the class final with a private constructor."],"exampleFix":"// before\nStringUtils su = new StringUtils();\n\n// after\nboolean empty = StringUtils.isEmpty(s);","handlingStrategy":"validation","validationCode":"if (Modifier.isFinal(StringUtils.class.getModifiers())) {\n  throw new IllegalStateException(\"StringUtils is static-only.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call StringUtils.isEmpty(...) etc.; never construct.","Register InstanceCreator/mixin for JSON fields typed as StringUtils.","Use Mockito.mockStatic for mocking.","Keep final + private constructor."],"tags":["android","utility-class","reflection","instantiation","string"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}