{"record":{"id":"7cc368190d00c7c2","repo":"quarkusio/quarkus","slug":"weigher-class-classname-must-implement-com-git","errorCode":null,"errorMessage":"Weigher class '<className>' must implement com.github.benmanes.caffeine.cache.Weigher","messagePattern":"Weigher class '<className>' must implement com\\.github\\.benmanes\\.caffeine\\.cache\\.Weigher","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/cache/QuarkusPersistenceUnitCaffeineCacheManager.java","lineNumber":114,"sourceCode":"            if (quarkusConfig.hasWeigherClass()) {\n                Weigher<K, V> weigher = instantiateWeigher(quarkusConfig.weigherClassName());\n                caffeineConfig.setWeigherFactory(Optional.of(() -> weigher));\n            }\n        } else {\n            // Count-based eviction (default)\n            caffeineConfig.setMaximumSize(OptionalLong.of(quarkusConfig.maxSize()));\n        }\n\n        caffeineConfig.setExpireAfterAccess(OptionalLong.of(quarkusConfig.maxIdle().toNanos()));\n        return delegate.createCache(cacheName, caffeineConfig);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private <K, V> Weigher<K, V> instantiateWeigher(String className) {\n        try {\n            Class<?> weigherClass = Thread.currentThread().getContextClassLoader().loadClass(className);\n            if (!Weigher.class.isAssignableFrom(weigherClass)) {\n                throw new IllegalStateException(\n                        \"Weigher class '\" + className + \"' must implement com.github.benmanes.caffeine.cache.Weigher\");\n            }\n            return (Weigher<K, V>) weigherClass.getConstructor().newInstance();\n        } catch (IllegalStateException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new IllegalStateException(\"Unable to instantiate weigher class: \" + className, e);\n        }\n    }\n\n    @Override\n    public Iterable<String> getCacheNames() {\n        return delegate.getCacheNames();\n    }\n\n    @Override\n    public void destroyCache(String cacheName) {\n        throw new UnsupportedOperationException(\"This should not be used by Hibernate ORM\");","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/cache/QuarkusPersistenceUnitCaffeineCacheManager.java#L96-L132","documentation":"When a 2nd-level cache region is configured with a custom Caffeine weigher, QuarkusPersistenceUnitCaffeineCacheManager.instantiateWeigher() loads the class by name and verifies it implements com.github.benmanes.caffeine.cache.Weigher. If the loaded class does not implement that interface, an IllegalStateException is thrown, failing persistence unit startup.","triggerScenarios":"Setting a cache region weigher class name (e.g. via quarkus.hibernate-orm.cache.<cache>.weigher or Hibernate cache config) where the class exists on the classpath but does not implement com.github.benmanes.caffeine.cache.Weigher.","commonSituations":"Pointing the weigher property at a Comparator, a CacheLoader, or a custom class that implements weigh() without implementing the Weigher interface; copying a class from an example that used a different caching abstraction; class name typos resolved to an unrelated same-named class.","solutions":["Make the configured class implement com.github.benmanes.caffeine.cache.Weigher<K,V> (and its weigh method returning a positive int).","Verify the fully-qualified class name in the config points to the intended weigher class, not a similarly named other class.","If you don't need weighted eviction, remove the weigher setting so Caffeine's default counting-based eviction is used.","Give the weigher class a public no-arg constructor so it can also pass the subsequent instantiation step."],"exampleFix":"// before\nclass MyWeigher { public int weigh(Object k, Object v) { return 1; } }\n\n// after\nimport com.github.benmanes.caffeine.cache.Weigher;\nclass MyWeigher implements Weigher<Object, Object> {\n  public int weigh(Object k, Object v) { return 1; }\n}","handlingStrategy":"validation","validationCode":"// Validate the weigher class before setting it in config\nClass<?> c = Class.forName(weigherClassName);\nif (!com.github.benmanes.caffeine.cache.Weigher.class.isAssignableFrom(c)) {\n    throw new IllegalStateException(weigherClassName + \" does not implement Caffeine Weigher\");\n}","typeGuard":"static boolean isValidWeigher(Class<?> c) {\n    return c != null\n        && com.github.benmanes.caffeine.cache.Weigher.class.isAssignableFrom(c);\n}","tryCatchPattern":"try {\n    startPu();\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"must implement com.github.benmanes.caffeine.cache.Weigher\")) {\n        log.error(\"Fix or remove quarkus.hibernate-orm.cache.<name>.weigher config\", e);\n    }\n    throw e;\n}","preventionTips":["Only configure classes that implement com.github.benmanes.caffeine.cache.Weigher","Test cache weigher config in a JVM-mode integration test before deploying","Prefer framework default eviction unless weighted eviction is truly needed"],"tags":["hibernate-orm","caffeine","cache","config","quarkus"],"backgroundTag":"class-does-not-implement-interface","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}