{"record":{"id":"ee5a8f7d545e4c83","repo":"apache/druid","slug":"key-s-is-not-registered-as-a-context-key","errorCode":null,"errorMessage":"Key [%s] is not registered as a context key","messagePattern":"Key \\[(.+?)\\] is not registered as a context key","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/context/ResponseContext.java","lineNumber":542,"sourceCode":"     * Register a group of keys.\n     */\n    public void registerKeys(Key[] keys)\n    {\n      for (Key key : keys) {\n        registerKey(key);\n      }\n    }\n\n    /**\n     * Returns a registered key associated with the name {@param name}.\n     *\n     * @throws IllegalStateException if a corresponding key has not been registered.\n     */\n    public Key keyOf(String name)\n    {\n      Key key = registeredKeys.get(name);\n      if (key == null) {\n        throw new ISE(\"Key [%s] is not registered as a context key\", name);\n      }\n      return key;\n    }\n\n    /**\n     * Returns a registered key associated with the given name, or\n     * {@code null} if the key is not registered. This form is for testing\n     * and for deserialization when the existence of the key is suspect.\n     */\n    public Key find(String name)\n    {\n      return registeredKeys.get(name);\n    }\n  }\n\n  protected abstract Map<Key, Object> getDelegate();\n\n  public Map<String, Object> toMap()","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java#L524-L560","documentation":"ResponseContext.BaseResponseContext.keyOf resolves a String name to a registered Key object and throws IllegalStateException when no key with that name has been registered. All response-context access must go through pre-registered keys, so an unregistered name is an invariant violation.","triggerScenarios":"Calling keyOf(\"someName\") where someName was never passed to registerKey/registerKeys — e.g. reading or writing a response context entry with a misspelled or extension-unknown key name.","commonSituations":"Typos in context key names; an extension that defines a key not loaded on this server (missing module); version skew where one node registers a key another node reads.","solutions":["Use keyOfOrNull(name) (the nullable variant) and handle the null case instead of keyOf","Register the key with registerKey/registerKeys before calling keyOf","Fix the key name typo; verify against the constants defined in ResponseContext.KeyType or the owning extension","Ensure all cluster nodes run the extensions that register the keys they exchange"],"exampleFix":"// before\nKey key = responseContext.keyOf(\"troughs\"); // ISE if not registered\n// after\nKey key = responseContext.keyOfOrNull(\"troughs\");\nif (key != null) { /* use it */ }","handlingStrategy":"validation","validationCode":"if (context.keyOfOrNull(name) == null) {\n  // handle unregistered key without throwing\n  return null;\n}","typeGuard":"Key keyOrNull(ResponseContext ctx, String name) { return ctx.keyOfOrNull(name); }","tryCatchPattern":"try { key = ctx.keyOf(name); } catch (IllegalStateException e) { key = null; /* skip this context entry */ }","preventionTips":["Reference key names via constants, never raw strings","Verify required extensions are loaded on all nodes","Use keyOfOrNull for optional keys"],"tags":["java","query-context","lookup"],"backgroundTag":"record-not-found","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}