{"record":{"id":"79632963b970d796","repo":"stanfordnlp/CoreNLP","slug":"unknown-seek-direction-seekdir","errorCode":null,"errorMessage":"Unknown seek direction \" + seekDir","messagePattern":"Unknown seek direction \" \\+ seekDir","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/ui/ParserPanel.java","lineNumber":225,"sourceCode":"      endIndex = textPane.getText().length() - 1;\n    }\n\n    highlightText(startIndex, endIndex, highlightStyle);\n\n    // enable/disable scroll buttons as necessary\n    backButton.setEnabled(startIndex != 0);\n    forwardButton.setEnabled(endIndex != textPane.getText().length() - 1);\n    parseNextButton.setEnabled(forwardButton.isEnabled() && parser != null);\n  }\n\n  /**\n   * Finds the nearest delimiter starting from index start. If <tt>seekDir</tt>\n   * is SEEK_FORWARD, finds the nearest delimiter after start.  Else, if it is\n   * SEEK_BACK, finds the nearest delimiter before start.\n   */\n  private int nearestDelimiter(String text, int start, int seekDir) {\n    if (seekDir != SEEK_BACK && seekDir != SEEK_FORWARD) {\n      throw new IllegalArgumentException(\"Unknown seek direction \" +\n                                         seekDir);\n    }\n    StringReader reader = new StringReader(text);\n    DocumentPreprocessor processor = new DocumentPreprocessor(reader);\n    TokenizerFactory<? extends HasWord> tf = tlp.getTokenizerFactory();\n    processor.setTokenizerFactory(tf);\n    List<Integer> boundaries = new ArrayList<>();\n    for (List<HasWord> sentence : processor) {\n      if (sentence.size() == 0)\n        continue;\n      if (!(sentence.get(0) instanceof HasOffset)) {\n        throw new ClassCastException(\"Expected HasOffsets from the \" +\n                                     \"DocumentPreprocessor\");\n      }\n      if (boundaries.size() == 0) {\n        boundaries.add(0);\n      } else {\n        HasOffset first = (HasOffset) sentence.get(0);","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/ui/ParserPanel.java#L207-L243","documentation":"ParserPanel.nearestDelimiter validates its seekDir parameter and throws IllegalArgumentException if it is neither SEEK_BACK nor SEEK_FORWARD. This is an internal guard for the GUI sentence-highlighting logic.","triggerScenarios":"Calling nearestDelimiter with a seekDir value other than ParserPanel.SEEK_FORWARD or ParserPanel.SEEK_BACK (only reachable programmatically, since the method is private and invoked from highlightSentence).","commonSituations":"Custom subclasses or edited copies of ParserPanel passing 0, -1, or an uninitialized field as direction; merge mistakes redefining the SEEK_* constants.","solutions":["Pass only ParserPanel.SEEK_FORWARD or ParserPanel.SEEK_BACK as seekDir","If in a copied/modified class, verify the SEEK_* constant values are unchanged (integers distinct from any other sentinel)","Ensure any state variable holding the direction is initialized to one of the two constants"],"exampleFix":"// before\nint dir = 0; // uninitialized\npanel.nearestDelimiter(text, start, dir);\n// after\nint dir = ParserPanel.SEEK_FORWARD;\npanel.nearestDelimiter(text, start, dir);","handlingStrategy":"validation","validationCode":"// only pass the panel's own constants\nassert (dir == ParserPanel.SEEK_BACK || dir == ParserPanel.SEEK_FORWARD);\nint idx = nearestDelimiter(text, start, dir);","typeGuard":"boolean isKnownSeekDir(int d) {\n  return d == ParserPanel.SEEK_BACK || d == ParserPanel.SEEK_FORWARD;\n}","tryCatchPattern":"try {\n  nearestDelimiter(text, start, dir);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unknown seek direction\")) {\n    dir = ParserPanel.SEEK_FORWARD;\n  } else throw e;\n}","preventionTips":["Only use SEEK_FORWARD/SEEK_BACK constants","Initialize direction fields at declaration","Don't redefine the constants in modified copies"],"tags":["swing","gui","argument-validation","java"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}