Skip to content

Commit 094731f

Browse files
committed
fix: resolve JCache createCache via Configuration interface, not MutableConfiguration
Class.getMethod requires exact parameter types and does not match supertypes. JSR-107 declares CacheManager#createCache(String, Configuration<K,V>), so the reflective lookup using MutableConfiguration always threw NoSuchMethodException when initializing JCacheAdapterReflective, forcing every JCache cache to fall back to Caffeine and flooding logs with errors at startup. Resolve the Configuration class via reflection in the appropriate namespace (javax or jakarta) and use it for the createCache method lookup. MutableConfiguration is still used to instantiate the configuration object since it is the concrete class created at runtime.
1 parent 8bb30ed commit 094731f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/org/fireflyframework/cache/factory/JCacheCacheHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,28 @@ private static class JCacheAdapterReflective implements CacheAdapter {
8686
Class<?> cmClass;
8787
Class<?> cacheClass;
8888
Class<?> mutableCfgClass;
89+
Class<?> cfgClass;
8990
boolean isJavax;
9091
try {
9192
cmClass = Class.forName("javax.cache.CacheManager", false, cl);
9293
cacheClass = Class.forName("javax.cache.Cache", false, cl);
9394
mutableCfgClass = Class.forName("javax.cache.configuration.MutableConfiguration", false, cl);
95+
cfgClass = Class.forName("javax.cache.configuration.Configuration", false, cl);
9496
isJavax = true;
9597
} catch (ClassNotFoundException ex) {
9698
cmClass = Class.forName("jakarta.cache.CacheManager", false, cl);
9799
cacheClass = Class.forName("jakarta.cache.Cache", false, cl);
98100
mutableCfgClass = Class.forName("jakarta.cache.configuration.MutableConfiguration", false, cl);
101+
cfgClass = Class.forName("jakarta.cache.configuration.Configuration", false, cl);
99102
isJavax = false;
100103
}
101104
this.javaxNamespace = isJavax;
102105

103106
this.getCacheMethod = cmClass.getMethod("getCache", String.class);
104-
this.createCacheMethod = cmClass.getMethod("createCache", String.class, mutableCfgClass);
107+
// JSR-107 CacheManager#createCache(String, Configuration) — declared parameter is the
108+
// Configuration interface. Class.getMethod requires exact parameter types and does not
109+
// match supertypes, so looking up MutableConfiguration here would throw NoSuchMethodException.
110+
this.createCacheMethod = cmClass.getMethod("createCache", String.class, cfgClass);
105111

106112
this.getValueMethod = cacheClass.getMethod("get", Object.class);
107113
this.putValueMethod = cacheClass.getMethod("put", Object.class, Object.class);

0 commit comments

Comments
 (0)