{"record":{"id":"80f75505b41874a1","repo":"quarkusio/quarkus","slug":"at-least-one-key-element-is-required-to-create-a-c","errorCode":null,"errorMessage":"At least one key element is required to create a composite cache key instance","messagePattern":"At least one key element is required to create a composite cache key instance","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/cache/runtime/src/main/java/io/quarkus/cache/CompositeCacheKey.java","lineNumber":22,"sourceCode":"\n/**\n * A composite cache key is used by the annotations caching API when a method annotated with {@link CacheResult} or\n * {@link CacheInvalidate} is invoked and when the cache key is composed of several of the method arguments (annotated with\n * {@link CacheKey} or not). This class can also be used with the programmatic caching API.\n */\npublic class CompositeCacheKey {\n\n    private final Object[] keyElements;\n\n    /**\n     * Constructor.\n     *\n     * @param keyElements key elements\n     * @throws IllegalArgumentException if no key elements are provided\n     */\n    public CompositeCacheKey(Object... keyElements) {\n        if (keyElements.length == 0) {\n            throw new IllegalArgumentException(\n                    \"At least one key element is required to create a composite cache key instance\");\n        }\n        this.keyElements = keyElements;\n    }\n\n    @Override\n    public int hashCode() {\n        return Arrays.deepHashCode(keyElements);\n    }\n\n    @Override\n    public boolean equals(Object obj) {\n        if (obj == this) {\n            return true;\n        }\n        if (CompositeCacheKey.class.isInstance(obj)) {\n            final CompositeCacheKey other = (CompositeCacheKey) obj;\n            return Arrays.deepEquals(keyElements, other.keyElements);","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/cache/runtime/src/main/java/io/quarkus/cache/CompositeCacheKey.java#L4-L40","documentation":"CompositeCacheKey combines the @CacheKey-annotated method parameters into one key object. Constructing it with zero elements would produce a key that cannot be distinguished, so the constructor throws IllegalArgumentException immediately.","triggerScenarios":"Calling `new CompositeCacheKey()` with no arguments; runtime path where a cached method has no @CacheKey parameters (or all key material was filtered out, e.g. Kotlin Continuation dropped) and the interceptor builds an empty key.","commonSituations":"Using @CacheResult/@CacheInvalidate on a method with zero parameters without a custom key generator; a custom KeyGenerator returning an empty varargs array into CompositeCacheKey.","solutions":["Ensure the cached method has at least one parameter annotated @CacheKey, or any parameter when defaults apply.","Provide a custom CacheKeyGenerator whose generate(...) returns a non-empty composite (pass at least one element to the constructor).","If the method genuinely has no key material, use a constant key: `new CompositeCacheKey(\"constant\")`."],"exampleFix":"// before\npublic class MyKeyGen implements CacheKeyGenerator {\n    public Object generate(Method m, Object... params) {\n        return new CompositeCacheKey(); // empty\n    }\n}\n\n// after\npublic Object generate(Method m, Object... params) {\n    return new CompositeCacheKey(params.length > 0 ? params : new Object[]{\"default-key\"});\n}","handlingStrategy":"validation","validationCode":"Object[] keyElements = collectKeyElements();\nif (keyElements == null || keyElements.length == 0) {\n    throw new IllegalArgumentException(\"CompositeCacheKey needs at least one element\");\n}\nCacheKey key = new CompositeCacheKey(keyElements);","typeGuard":null,"tryCatchPattern":"try {\n    CacheKey key = new CompositeCacheKey(elements);\n} catch (IllegalArgumentException e) {\n    // fall back to a constant key\n    key = new CompositeCacheKey(\"default\");\n}","preventionTips":["Annotate cached-method parameters with @CacheKey","Never return an empty array from a custom CacheKeyGenerator","For parameterless cached methods, supply a constant key element"],"tags":["quarkus","cache","cachekey","illegal-argument"],"backgroundTag":"empty-cache-key","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}