stanfordnlp/CoreNLP · error · IllegalArgumentException

Invalid contraction provided to processContraction

Error message

Invalid contraction provided to processContraction

What it means

FrenchTokenizer splits known French contractions (e.g. 'au', 'du', 'aux') into two tokens; processContraction uses a switch over the contracted word. If the token passed in is not one of the handled contractions, the default branch throws this IllegalArgumentException.

Solutions

  1. Add a case for the missing contraction in processContraction's switch with its first/second split and offsets
  2. Update the contraction-matching regex so only contractions handled by the switch reach processContraction
  3. Check FrenchTokenizer source for the complete list of supported contractions

Example fix

// before
default:
  throw new IllegalArgumentException("Invalid contraction provided to processContraction");
// after
case "poui":
  first = "pou"; second = "hi"; secondOffset = 3; secondLength = 2;
  break;
default:
  throw new IllegalArgumentException("Invalid contraction provided to processContraction: " + cl.word());
Defensive patterns

Strategy: try-catch

Validate before calling

private static final java.util.Set<String> SUPPORTED = java.util.Set.of("au","aux","du","ou","son");
if (!SUPPORTED.contains(word)) return java.util.Collections.singletonList(cl);

Try / catch

try { tokens.addAll(processContraction(cl)); } catch (IllegalArgumentException e) { log.warn("Unhandled contraction: " + cl.word()); tokens.add(cl); }

Prevention

When it happens

Trigger: getNext() calls processContraction with a CoreLabel whose word is not in the supported set of French contractions, typically due to a code change adding a new contraction to a matcher without a corresponding case.

Common situations: Extending the tokenizer to handle additional contractions (e.g. 'poui' or regional forms) but forgetting to add the split in processContraction; version drift between the contraction regex and the switch.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/french/process/FrenchTokenizer.java:195

        first = "à";
        second = "le";
        secondOffset = 1;
        secondLength = 1;
        break;
      case "aux":
        first = "à";
        second = "les";
        secondOffset = 1;
        secondLength = 2;
        break;
      case "du":
        first = "de";
        second = "le";
        secondOffset = 1;
        secondLength = 1;
        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);
  }


  /**
   * A factory for French tokenizer instances.
   *
   * @author Spence Green
   */
  public static class FrenchTokenizerFactory<T extends HasWord> implements TokenizerFactory<T>, Serializable  {

    private static final long serialVersionUID = 946818805507187330L;

View on GitHub (pinned to 1b7edd19c4)