{"record":{"id":"100545b4fb41c644","repo":"apache/druid","slug":"expected-key-s-to-be-referring-to-one-of-the-va","errorCode":null,"errorMessage":"Expected key [%s] to be referring to one of the values [%s] of enum [%s], but got [%s]","messagePattern":"Expected key \\[(.+?)\\] to be referring to one of the values \\[(.+?)\\] of enum \\[(.+?)\\], but got \\[(.+?)\\]","errorType":"validation","errorClass":"BadQueryContextException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/QueryContexts.java","lineNumber":569,"sourceCode":"  }\n\n\n  @Nullable\n  public static <E extends Enum<E>> E getAsEnum(String key, Object value, Class<E> clazz)\n  {\n    if (value == null) {\n      return null;\n    }\n\n    try {\n      if (value instanceof String) {\n        return Enum.valueOf(clazz, StringUtils.toUpperCase((String) value));\n      } else if (value instanceof Boolean) {\n        return Enum.valueOf(clazz, StringUtils.toUpperCase(String.valueOf(value)));\n      }\n    }\n    catch (IllegalArgumentException e) {\n      throw badValueException(\n          key,\n          StringUtils.format(\n              \"referring to one of the values [%s] of enum [%s]\",\n              Arrays.stream(clazz.getEnumConstants()).map(Enum::name).collect(\n                  Collectors.joining(\",\")),\n              clazz.getSimpleName()\n          ),\n          value\n      );\n    }\n\n    throw badTypeException(\n        key,\n        StringUtils.format(\"of type [%s]\", clazz.getSimpleName()),\n        value\n    );\n  }\n","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/QueryContexts.java#L551-L587","documentation":"Druid's QueryContexts.getAsEnum converts a query context value into an enum constant by upper-casing the value and calling Enum.valueOf. When the value does not name any constant of the target enum, the IllegalArgumentException from valueOf is rethrown as a BadQueryContextException listing the valid enum values. It exists so query context keys carrying enum-typed settings fail fast with an actionable message instead of silently misbehaving.","triggerScenarios":"Setting a query context key that is parsed as an enum (e.g. via QueryContexts.getEnum or context-aware query options) to a string or boolean that does not match any constant of the target enum class, such as context {\"vectorize\":\"yess\"} where the enum only has TRUE/FALSE or NONE.","commonSituations":"Typos in query context JSON submitted via SQL (SET clauses) or the native query API; copying context values from an older Druid version where an enum constant was renamed or removed; passing boolean-like strings ('yes'/'on') where only the enum's constant names are accepted.","solutions":["Read the error message's list of valid values and set the context key to one of the listed enum constant names (case-insensitive).","Check the Druid version's documentation for the specific context key; enum constants may differ across versions.","If the value is computed dynamically, validate it against Enum.valueOf(clazz, value.toUpperCase()) before putting it in the query context."],"exampleFix":"// before\nquery.setContextValue(\"vectorize\", \"yess\");\n// after\nquery.setContextValue(\"vectorize\", \"true\");","handlingStrategy":"validation","validationCode":"// Java\nboolean valid = Arrays.stream(MyEnum.values()).anyMatch(e -> e.name().equalsIgnoreCase(value));\nif (!valid) throw new IllegalArgumentException(\"context value must be one of \" + Arrays.toString(MyEnum.values()));","typeGuard":"static <E extends Enum<E>> boolean isEnumValue(Object v, Class<E> clazz) {\n  return (v instanceof String && Arrays.stream(clazz.getEnumConstants()).anyMatch(e -> e.name().equalsIgnoreCase((String) v)))\n      || (v instanceof Boolean && Arrays.stream(clazz.getEnumConstants()).anyMatch(e -> e.name().equalsIgnoreCase(String.valueOf(v))));\n}","tryCatchPattern":"try {\n  query.addContext(\"vectorize\", value);\n} catch (BadQueryContextException e) {\n  log.error(\"Rejecting bad context value: {}\", e.getMessage());\n  throw new IllegalArgumentException(\"Invalid enum context value\", e);\n}","preventionTips":["Whitelist context values against Enum.valueOf(...) before submitting queries.","Use the query's typed context API instead of raw string maps.","Pin context key names/values to a specific Druid version and re-check on upgrades."],"tags":["druid","query-context","enum","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}