stanfordnlp/CoreNLP · error · IllegalArgumentException

Invalid contraction provided to processContraction

Error message

Invalid contraction provided to processContraction

What it means

SpanishTokenizer.processContraction splits known Spanish contractions (e.g. 'del', 'al', compound forms with'+word) into two tokens. The switch on the contraction's word length/shape has no case matching the input, so the method throws this IllegalArgumentException. It indicates the token routed to contraction splitting is not one of the recognized contraction forms.

Solutions

  1. Inspect the offending word in the input text and confirm it is a valid Spanish contraction handled by the tokenizer.
  2. Adjust tokenization options (e.g. disable splitVerbs/contraction splitting) if the text legitimately contains forms the splitter does not handle.
  3. Pre-normalize the input (strip stray apostrophes/quotes) so the contraction matcher only sees genuine contractions.
  4. Upgrade or patch CoreNLP so the contraction candidate check in getNext matches the cases in processContraction.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  CoreLabel tok = tokenizer.next();
  buffer.add(tok);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("processContraction")) {
    log.warn("Skipping token that failed contraction splitting");
  } else throw e;
}

Prevention

When it happens

Trigger: getNext identifies a word as a contraction candidate and calls processContraction, but the word does not match any expected contraction pattern in the switch (default branch). Typically caused by an unexpected surface form that passed an earlier heuristic, or by feeding text where SpanishTokenizer-specific contraction rules do not apply to the token shape.

Common situations: Processing text containing apostrophe/clitic sequences that resemble contractions but are not among the handled forms; running with spanishTokenization options that enable contraction splitting on edge-case inputs; version mismatches where the caller's candidate list and processContraction's cases diverge.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/spanish/process/SpanishTokenizer.java:181

        else second = "EL";
        secondOffset = 1;
        secondLength = lowered.length() - 1;
        break;
      case "conmigo":
      case "consigo":
        first = word.substring(0, 3);
        second = word.charAt(3) + "í";
        secondOffset = 3;
        secondLength = 4;
        break;
      case "contigo":
        first = word.substring(0, 3);
        second = word.substring(3, 5);
        secondOffset = 3;
        secondLength = 4;
        break;
      default:
        throw new IllegalArgumentException("Invalid contraction provided to processContraction");
    }

    int secondStart = cl.beginPosition() + secondOffset;
    int secondEnd = secondStart + secondLength;
    compoundBuffer.add(copyCoreLabel(cl, second, secondStart, secondEnd));
    return copyCoreLabel(cl, first, cl.beginPosition(), secondStart);
  }

  /**
   * Handles verbs with attached suffixes, marked by the lexer:
   *
   * Escribamosela => Escribamo + se + la => escribamos + se + la
   * Sentaos => senta + os => sentad + os
   * Damelo => da + me + lo
   *
   */
  private CoreLabel processVerb(CoreLabel cl) {
    cl.remove(ParentAnnotation.class);

View on GitHub (pinned to 1b7edd19c4)