{"record":{"id":"d1053fe1da014f59","repo":"alibaba/spring-ai-alibaba","slug":"utility-class-cannot-be-instantiated","errorCode":null,"errorMessage":"Utility class cannot be instantiated","messagePattern":"Utility class cannot be instantiated","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/constant/StoreConstant.java","lineNumber":53,"sourceCode":"\n\t/**\n\t * Store type identifiers\n\t */\n\tpublic static final String STORE_TYPE_MEMORY = \"memory\";\n\n\tpublic static final String STORE_TYPE_REDIS = \"redis\";\n\n\tpublic static final String STORE_TYPE_FILESYSTEM = \"filesystem\";\n\n\tpublic static final String STORE_TYPE_MONGODB = \"mongodb\";\n\n\tpublic static final String STORE_TYPE_DATABASE = \"database\";\n\n\t/**\n\t * Private constructor to prevent instantiation.\n\t */\n\tprivate StoreConstant() {\n\t\tthrow new UnsupportedOperationException(\"Utility class cannot be instantiated\");\n\t}\n\n}\n","sourceCodeStart":35,"sourceCodeEnd":57,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/constant/StoreConstant.java#L35-L57","documentation":"StoreConstant is a constants-only utility class with a private constructor that throws UnsupportedOperationException if instantiated (directly or reflectively). It is a design guard, not a runtime failure of library logic.","triggerScenarios":"Calling new StoreConstant(), or reflection/instantiation frameworks (Jackson, Spring bean scanning, code coverage tooling) attempting to construct the class.","commonSituations":"Accidentally adding StoreConstant as a Spring bean; reflective instantiation in generic serialization code; IDE auto-generating a test that constructs the utility class.","solutions":["Do not instantiate; reference the public static constants directly (e.g. StoreConstant.STORE_TYPE_DATABASE)","If a framework requires instantiation, exclude the class from scanning/serialization","In tests, assert the constructor throws rather than constructing it via normal means"],"exampleFix":"// before\nStoreConstant constants = new StoreConstant();\nString type = constants.STORE_TYPE_DATABASE;\n// after\nString type = StoreConstant.STORE_TYPE_DATABASE;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"if (obj instanceof StoreConstant) { throw new AssertionError(\"StoreConstant must not be instantiated\"); }","tryCatchPattern":"try { ctor = StoreConstant.class.getDeclaredConstructor(); ctor.setAccessible(true); ctor.newInstance(); } catch (InvocationTargetException e) { /* expected: UnsupportedOperationException */ }","preventionTips":["Always use the static constants directly","Exclude utility classes from bean scanning and reflective instantiation"],"tags":["java","utility-class","instantiation","design-guard"],"backgroundTag":"unsupported-operation","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}