{"record":{"id":"4154d8e191b0fa4b","repo":"apache/dubbo","slug":"no-instance-of-filecachestorefactory-for-you","errorCode":null,"errorMessage":"No instance of 'FileCacheStoreFactory' for you! ","messagePattern":"No instance of 'FileCacheStoreFactory' for you! ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java","lineNumber":51,"sourceCode":"import java.util.HashSet;\nimport java.util.Set;\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.concurrent.ConcurrentMap;\n\nimport static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.USER_HOME;\nimport static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CACHE_PATH_INACCESSIBLE;\n\n/**\n * ClassLoader Level static share.\n * Prevent FileCacheStore being operated in multi-application\n */\npublic final class FileCacheStoreFactory {\n\n    /**\n     * Forbids instantiation.\n     */\n    private FileCacheStoreFactory() {\n        throw new UnsupportedOperationException(\"No instance of 'FileCacheStoreFactory' for you! \");\n    }\n\n    private static final ErrorTypeAwareLogger logger =\n            LoggerFactory.getErrorTypeAwareLogger(FileCacheStoreFactory.class);\n    private static final ConcurrentMap<String, FileCacheStore> cacheMap = new ConcurrentHashMap<>();\n\n    private static final String SUFFIX = \".dubbo.cache\";\n    private static final char ESCAPE_MARK = '%';\n    private static final Set<Character> LEGAL_CHARACTERS = Collections.unmodifiableSet(new HashSet<Character>() {\n        {\n            // - $ . _ 0-9 a-z A-Z\n            add('-');\n            add('$');\n            add('.');\n            add('_');\n            for (char c = '0'; c <= '9'; c++) {\n                add(c);\n            }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java#L33-L69","documentation":"Thrown from the private constructor of FileCacheStoreFactory, which is a utility class meant to be used only via its static getInstance methods. Instantiating it directly (including via reflection) is forbidden and immediately fails.","triggerScenarios":"Code calls new FileCacheStoreFactory() directly, or reflection (Constructor.newInstance) invokes the private constructor. The constructor is private and throws, so both normal and reflective instantiation fail.","commonSituations":"A framework (Spring, a test util, a serialization lib) tries to instantiate the class reflectively. A developer unfamiliar with the API attempts to new it up instead of calling getInstance.","solutions":["Never instantiate FileCacheStoreFactory; always call FileCacheStoreFactory.getInstance(basePath, cacheName).","If a DI framework tries to construct it, exclude it from component scanning or mark it as a static utility.","For tests, mock the FileCacheStore returned by getInstance rather than the factory itself."],"exampleFix":"// before\nFileCacheStoreFactory f = new FileCacheStoreFactory();  // throws\n// after\nFileCacheStore cache = FileCacheStoreFactory.getInstance(null, \"meta\");","handlingStrategy":"validation","validationCode":"// Never instantiate the factory; always use the static accessor\nFileCacheStore cache = FileCacheStoreFactory.getInstance(basePath, cacheName);","typeGuard":null,"tryCatchPattern":"try {\n    FileCacheStoreFactory.class.getDeclaredConstructor().setAccessible(true);\n    // ... instantiation attempt\n} catch (UnsupportedOperationException | ReflectiveOperationException e) {\n    // factory cannot be instantiated; use getInstance instead\n}","preventionTips":["Always call FileCacheStoreFactory.getInstance instead of constructing it.","Exclude utility classes from DI component scanning.","Mock the returned FileCacheStore in tests, not the factory."],"tags":["cache","utility-class","instantiation","reflection"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}