stanfordnlp/CoreNLP · error · UnsupportedOperationException

Unsupported findType

Error message

Unsupported findType 

What it means

SequenceMatcher.find() dispatches on the matcher's findType, which is set at construction (FIND_NONOVERLAPPING or FIND_ALL). If findType holds any other value, the switch falls through to default and throws UnsupportedOperationException. This guards against invalid or future findType values reaching the find loop.

Solutions

  1. Only use SequenceMatcher.FindType.FIND_NONOVERLAPPING or FIND_ALL when creating the matcher
  2. If you need a new find mode, add a case to the switch in find() (and findMatchStart) instead of passing an unknown type
  3. Check that no custom subclass or reflection is overwriting the findType field
  4. Upgrade/downgrade CoreNLP so the FindType constants match the SequenceMatcher implementation in use

Example fix

// before
matcher.setFindType(someCustomFindType);
matcher.find();
// after
matcher.setFindType(SequenceMatcher.FindType.FIND_NONOVERLAPPING);
matcher.find();
Defensive patterns

Strategy: validation

Validate before calling

if (findType != SequenceMatcher.FindType.FIND_NONOVERLAPPING && findType != SequenceMatcher.FindType.FIND_ALL) {
  throw new IllegalArgumentException("findType must be FIND_NONOVERLAPPING or FIND_ALL: " + findType);
}

Type guard

boolean isValidFindType(SequenceMatcher.FindType t) {
  return t == SequenceMatcher.FindType.FIND_NONOVERLAPPING || t == SequenceMatcher.FindType.FIND_ALL;
}

Try / catch

try {
  matcher.find();
} catch (UnsupportedOperationException e) {
  log.error("Unsupported findType on matcher", e);
  // recreate matcher with default FIND_NONOVERLAPPING
}

Prevention

When it happens

Trigger: Calling find() on a SequenceMatcher whose findType field is not one of the two supported constants — typically only possible by constructing the matcher with an invalid FindType or mutating it reflectively, since the public API normally only exposes the two constants.

Common situations: Custom code that defines or passes a new FindType constant, or code copied from a newer/older Stanford CoreNLP version where an additional find type exists but the matcher implementation does not support it in find().

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/SequenceMatcher.java:472

        throw new UnsupportedOperationException();
      }
    };
    return new IterableIterator<>(iter);
  }

  /**
   * Searches for the next occurrence of the pattern
   * @return true if a match is found (false otherwise)
   * @see #find(int)
   */
  public boolean find() {
    switch (findType) {
      case FIND_NONOVERLAPPING:
        return findNextNonOverlapping();
      case FIND_ALL:
        return findNextAll();
      default:
        throw new UnsupportedOperationException("Unsupported findType " + findType);
    }
  }

  private boolean findMatchStart(int start, boolean matchAllTokens) {
    switch (findType) {
      case FIND_NONOVERLAPPING:
        return findMatchStartBacktracking(start, matchAllTokens);
      case FIND_ALL:
        // TODO: Should use backtracking here too, need to keep track of todo stack
        // so we can recover after finding a match
        return findMatchStartNoBacktracking(start, matchAllTokens);
      default:
        throw new UnsupportedOperationException("Unsupported findType " + findType);
    }
  }

  // Does not do backtracking - alternative matches are stored as we go
  private boolean findMatchStartNoBacktracking(int start, boolean matchAllTokens) {

View on GitHub (pinned to 1b7edd19c4)