{"record":{"id":"958783ad49dfd2a8","repo":"quarkusio/quarkus","slug":"key-already-registered-key","errorCode":null,"errorMessage":"Key already registered ${key}","messagePattern":"Key already registered (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/runtime/src/main/java/io/quarkus/runtime/ValueRegistryImpl.java","lineNumber":52,"sourceCode":"        if (key == null || key.key() == null) {\n            throw new IllegalArgumentException(\"Key cannot be null\");\n        }\n        if (value == null) {\n            throw new IllegalArgumentException(\"Value cannot be null\");\n        }\n        registerInfo(key, SimpleRuntimeInfo.of(value));\n    }\n\n    public <T> void registerInfo(final RuntimeKey<T> key, final RuntimeInfo<T> runtimeInfo) {\n        if (key == null || key.key() == null) {\n            throw new IllegalArgumentException(\"Key cannot be null\");\n        }\n        if (runtimeInfo == null) {\n            throw new IllegalArgumentException(\"Value cannot be null\");\n        }\n        RuntimeInfo<?> mapValue = values.putIfAbsent(key.key(), runtimeInfo);\n        if (mapValue != null) {\n            throw new IllegalArgumentException(\"Key already registered \" + key.key());\n        }\n    }\n\n    public <T> boolean containsKey(final RuntimeKey<T> key) {\n        return values.containsKey(key.key());\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public <T> T get(final RuntimeKey<T> key) {\n        RuntimeInfo<T> runtimeInfo = (RuntimeInfo<T>) values.get(key.key());\n        if (runtimeInfo == null) {\n            throw new IllegalArgumentException(\"Key \" + key.key() + \" not found\");\n        }\n        return runtimeInfo.get(this);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public <T> T getOrDefault(final RuntimeKey<T> key, final T defaultValue) {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/runtime/src/main/java/io/quarkus/runtime/ValueRegistryImpl.java#L34-L70","documentation":"The registry stores one RuntimeInfo per key using putIfAbsent; if the key already exists it throws IllegalArgumentException('Key already registered <key>'). Registration is first-write-wins — re-registering is treated as a programming error rather than an update.","triggerScenarios":"Calling register()/registerInfo() twice with the same RuntimeKey, e.g. two build steps or two extension processors registering the same key, or an app restarted registration logic within one runtime instance.","commonSituations":"Duplicate registration from two versions of an extension on the classpath; test code re-running setup without a fresh registry; accidental copy-paste of a key constant.","solutions":["Guard with registry.containsKey(key) before registering, or use getOrDefault-style access.","Deduplicate the key: give each registrar a unique key.","If intentional override is needed, use a different API (clear/replace) rather than register."],"exampleFix":"// before\nregistry.register(MyKeys.POOL_SIZE, 10);\nregistry.register(MyKeys.POOL_SIZE, 20); // throws\n// after\nif (!registry.containsKey(MyKeys.POOL_SIZE)) {\n    registry.register(MyKeys.POOL_SIZE, 20);\n}","handlingStrategy":"validation","validationCode":"if (!registry.containsKey(key)) {\n    registry.register(key, value);\n}","typeGuard":"boolean isUnregistered(ValueRegistryImpl registry, RuntimeKey<?> key) {\n    return !registry.containsKey(key);\n}","tryCatchPattern":"try {\n    registry.register(key, value);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Key already registered\")) {\n        log.debugf(\"Key %s already registered; keeping existing value\", key.key());\n    } else { throw e; }\n}","preventionTips":["Check containsKey before registering","Give each registrar/extension a unique key namespace","Use a singleton registrar to centralize all registrations"],"tags":["duplicate-key","registry","illegal-argument"],"backgroundTag":"duplicate-key-registration","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"}