stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown seek direction " + seekDir

Error message

Unknown seek direction " + seekDir

What it means

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.

Solutions

  1. Pass only ParserPanel.SEEK_FORWARD or ParserPanel.SEEK_BACK as seekDir
  2. If in a copied/modified class, verify the SEEK_* constant values are unchanged (integers distinct from any other sentinel)
  3. Ensure any state variable holding the direction is initialized to one of the two constants

Example fix

// before
int dir = 0; // uninitialized
panel.nearestDelimiter(text, start, dir);
// after
int dir = ParserPanel.SEEK_FORWARD;
panel.nearestDelimiter(text, start, dir);
Defensive patterns

Strategy: validation

Validate before calling

// only pass the panel's own constants
assert (dir == ParserPanel.SEEK_BACK || dir == ParserPanel.SEEK_FORWARD);
int idx = nearestDelimiter(text, start, dir);

Type guard

boolean isKnownSeekDir(int d) {
  return d == ParserPanel.SEEK_BACK || d == ParserPanel.SEEK_FORWARD;
}

Try / catch

try {
  nearestDelimiter(text, start, dir);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Unknown seek direction")) {
    dir = ParserPanel.SEEK_FORWARD;
  } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: Custom subclasses or edited copies of ParserPanel passing 0, -1, or an uninitialized field as direction; merge mistakes redefining the SEEK_* constants.

Understand the failure class

Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/79632963b970d796. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/ui/ParserPanel.java:225

      endIndex = textPane.getText().length() - 1;
    }

    highlightText(startIndex, endIndex, highlightStyle);

    // enable/disable scroll buttons as necessary
    backButton.setEnabled(startIndex != 0);
    forwardButton.setEnabled(endIndex != textPane.getText().length() - 1);
    parseNextButton.setEnabled(forwardButton.isEnabled() && parser != null);
  }

  /**
   * Finds the nearest delimiter starting from index start. If <tt>seekDir</tt>
   * is SEEK_FORWARD, finds the nearest delimiter after start.  Else, if it is
   * SEEK_BACK, finds the nearest delimiter before start.
   */
  private int nearestDelimiter(String text, int start, int seekDir) {
    if (seekDir != SEEK_BACK && seekDir != SEEK_FORWARD) {
      throw new IllegalArgumentException("Unknown seek direction " +
                                         seekDir);
    }
    StringReader reader = new StringReader(text);
    DocumentPreprocessor processor = new DocumentPreprocessor(reader);
    TokenizerFactory<? extends HasWord> tf = tlp.getTokenizerFactory();
    processor.setTokenizerFactory(tf);
    List<Integer> boundaries = new ArrayList<>();
    for (List<HasWord> sentence : processor) {
      if (sentence.size() == 0)
        continue;
      if (!(sentence.get(0) instanceof HasOffset)) {
        throw new ClassCastException("Expected HasOffsets from the " +
                                     "DocumentPreprocessor");
      }
      if (boundaries.size() == 0) {
        boundaries.add(0);
      } else {
        HasOffset first = (HasOffset) sentence.get(0);

View on GitHub (pinned to 1b7edd19c4)