alibaba/spring-ai-alibaba · warning · UnsupportedOperationException
Utility class cannot be instantiated
Error message
Utility class cannot be instantiated
What it means
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.
Source
Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/constant/StoreConstant.java:53
/**
* Store type identifiers
*/
public static final String STORE_TYPE_MEMORY = "memory";
public static final String STORE_TYPE_REDIS = "redis";
public static final String STORE_TYPE_FILESYSTEM = "filesystem";
public static final String STORE_TYPE_MONGODB = "mongodb";
public static final String STORE_TYPE_DATABASE = "database";
/**
* Private constructor to prevent instantiation.
*/
private StoreConstant() {
throw new UnsupportedOperationException("Utility class cannot be instantiated");
}
}
View on GitHub (pinned to f82da0b50f)
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
Example fix
// before StoreConstant constants = new StoreConstant(); String type = constants.STORE_TYPE_DATABASE; // after String type = StoreConstant.STORE_TYPE_DATABASE;
Defensive patterns
Strategy: type-guard
Type guard
if (obj instanceof StoreConstant) { throw new AssertionError("StoreConstant must not be instantiated"); } Try / catch
try { ctor = StoreConstant.class.getDeclaredConstructor(); ctor.setAccessible(true); ctor.newInstance(); } catch (InvocationTargetException e) { /* expected: UnsupportedOperationException */ } Prevention
- Always use the static constants directly
- Exclude utility classes from bean scanning and reflective instantiation
When it happens
Trigger: Calling new StoreConstant(), or reflection/instantiation frameworks (Jackson, Spring bean scanning, code coverage tooling) attempting to construct the class.
Common situations: Accidentally adding StoreConstant as a Spring bean; reflective instantiation in generic serialization code; IDE auto-generating a test that constructs the utility class.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Utility class
- Utility class
- Elastic search index name must be provided
- Param Not Support Object
- Param Not Support Array<Object>
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/d1053fe1da014f59.
Report an issue: GitHub.