stanfordnlp/CoreNLP · error · IllegalStateException

Unhandled case: " + mono + " and " + type

Error message

Unhandled case: " + mono + " and " + type

What it means

monotonicitySignature maps a Monotonicity + MonotonicityType pair back to its canonical string form (e.g. "anti-additive"). If the combination falls outside the enumerated matrix of monotone/antitone x additive/multiplicative/both plus NONMONOTONE, the switch returns nothing and the method throws IllegalStateException. This should be unreachable with valid enum values and signals a real logic bug if seen.

Solutions

  1. Inspect the mono and type values being passed; ensure they come from the standard Operator enum combinations
  2. Add the missing case to the switch if a new Monotonicity/MonotonicityType constant was introduced
  3. Guard for null before calling the method

Example fix

// before
String sig = Operator.monotonicitySignature(mono, null);
// after
String sig = (mono == null || type == null) ? "nonmonotone" : Operator.monotonicitySignature(mono, type);
Defensive patterns

Strategy: validation

Validate before calling

if (mono == null || type == null) { sig = "nonmonotone"; } else { sig = Operator.monotonicitySignature(mono, type); }

Try / catch

try { sig = Operator.monotonicitySignature(mono, type); } catch (IllegalStateException e) { sig = "nonmonotone"; }

Prevention

When it happens

Trigger: Calling Operator.monotonicitySignature(mono, type) with a Monotonicity/MonotonicityType combination not covered by the switch — typically only possible with a null enum value, a corrupted/deserialized enum, or a newly added enum constant not yet handled.

Common situations: After upgrading CoreNLP and hand-crafting Operator definitions; passing null MonotonicityType for MONOTONE/NONMONOTONE cases in code that builds signatures dynamically.

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/b5ea416439698ff8. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/naturalli/Operator.java:175

  public static String monotonicitySignature(Monotonicity mono, MonotonicityType type) {
    switch (mono) {
      case MONOTONE:
        switch (type) {
          case NONE: return "nonmonotone";
          case ADDITIVE: return "additive";
          case MULTIPLICATIVE: return "multiplicative";
          case BOTH: return "additive-multiplicative";
        }
      case ANTITONE:
        switch (type) {
          case NONE: return "nonmonotone";
          case ADDITIVE: return "anti-additive";
          case MULTIPLICATIVE: return "anti-multiplicative";
          case BOTH: return "anti-additive-multiplicative";
        }
      case NONMONOTONE: return "nonmonotone";
    }
    throw new IllegalStateException("Unhandled case: " + mono + " and " + type);
  }

  @SuppressWarnings("UnusedDeclaration")
  public static final Set<String> quantifierGlosses = Collections.unmodifiableSet(new HashSet<String>() {{
    for (Operator operator : values()) {
      add(operator.surfaceForm);
    }
  }});

  public static Optional<Operator> fromString(String word) {
    String wordToLowerCase = word.toLowerCase().replaceAll("[0-9]", "--num-- ").trim();
    for (Operator candidate : Operator.values()) {
      if (candidate.surfaceForm.equals(wordToLowerCase)) {
        return Optional.of(candidate);
      }
    }
    return Optional.empty();
  }

View on GitHub (pinned to 1b7edd19c4)