{"record":{"id":"bf1b31b2a00a927a","repo":"stanfordnlp/CoreNLP","slug":"unknown-mode","errorCode":null,"errorMessage":"Unknown mode ","messagePattern":"Unknown mode ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/ArrayStringFilter.java","lineNumber":66,"sourceCode":"    case PREFIX:\n      if (input == null) {\n        return false;\n      }\n      for (int i = 0; i < length; ++i) {\n        if (input.startsWith(words[i])) {\n          return true;\n        }\n      }\n      return false;\n    case CASE_INSENSITIVE:\n      for (int i = 0; i < length; ++i) {\n        if (words[i].equalsIgnoreCase(input)) {\n          return true;\n        }\n      }\n      return false;\n    default:\n      throw new IllegalArgumentException(\"Unknown mode \" + mode);\n    }\n  }\n\n  @Override\n  public String toString() {\n    return mode.toString() + ':' + StringUtils.join(words, \",\");\n  }\n\n  @Override\n  public int hashCode() {\n    int result = 1;\n    for (String word : words) {\n      result += word.hashCode();\n    }\n    return result;\n  }\n\n  @Override","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/ArrayStringFilter.java#L48-L84","documentation":"ArrayStringFilter.test() switches over the filter's Mode enum; if mode is not one of the three known values (EXACT, PREFIX, CASE_INSENSITIVE), the default branch throws IllegalArgumentException('Unknown mode ' + mode). This guards against a Mode enum that was extended in a newer library version while the switch was not updated.","triggerScenarios":"Calling test() on an ArrayStringFilter whose mode is a newly added or unknown Mode constant not handled by this switch, e.g. a filter constructed in a different library version or via reflection/deserialization with an unexpected mode.","commonSituations":"Mixing library versions (serializing/deserializing filters across versions where Mode has extra constants); extending the Mode enum locally without updating test(); Java enum deserialization producing a constant unknown to the installed version.","solutions":["Upgrade/downgrade so the ArrayStringFilter version matches the one that created the filter, ensuring the Mode constant exists in both.","Ensure the filter is only constructed with Mode.EXACT, Mode.PREFIX, or Mode.CASE_INSENSITIVE.","If you control the enum, add a case for the new constant in the switch before using the filter."],"exampleFix":"// before\nMode mode = MyCustomModes.SUFFIX; // not handled by ArrayStringFilter\nArrayStringFilter f = new ArrayStringFilter(mode, \"x\");\n// after\nArrayStringFilter f = new ArrayStringFilter(ArrayStringFilter.Mode.PREFIX, \"x\");","handlingStrategy":"type-guard","validationCode":"if (mode != ArrayStringFilter.Mode.EXACT && mode != ArrayStringFilter.Mode.PREFIX && mode != ArrayStringFilter.Mode.CASE_INSENSITIVE) {\n  throw new IllegalArgumentException(\"unsupported mode: \" + mode);\n}","typeGuard":"boolean isSupportedMode(ArrayStringFilter.Mode m) {\n  return m == ArrayStringFilter.Mode.EXACT || m == ArrayStringFilter.Mode.PREFIX || m == ArrayStringFilter.Mode.CASE_INSENSITIVE;\n}","tryCatchPattern":"try {\n  boolean hit = filter.test(input);\n} catch (IllegalArgumentException e) {\n  // recreate the filter with a known Mode and retry\n}","preventionTips":["Keep serialization/deserialization of filters on the same library version on both sides.","Construct filters only with constants from ArrayStringFilter.Mode, never via reflection.","If you extend Mode, update the test() switch in the same change."],"tags":["java","enum","switch","unhandled-case"],"backgroundTag":"unsupported-enum-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}