stanfordnlp/CoreNLP · error · UnsupportedOperationException

Unknown compType

Error message

Unknown compType: ${compType}

What it means

ValueFunctions' comparison helper throws UnsupportedOperationException when the ComparisonFunction's compType is not one of GT, LT, GE, LE, EQ, NE. compType is normally parsed from the expression operator, so this means an unknown/unmapped comparison type reached compareTo.

Solutions

  1. Set compType to one of the supported tokens: GT, LT, GE, LE, EQ, NE.
  2. Verify the operator in the expression string parses to a valid compType (e.g. '>', '<', '>=', '<=', '==', '!=').
  3. If adding a custom compType, extend the compareTo switch to handle it instead of relying on the default branch.

Example fix

// before
Expressions.CompareExpression e = new Expressions.CompareExpression("x", myValue, null);
// after
Expressions.CompareExpression e = new Expressions.CompareExpression("x", myValue, Expressions.ComparisonType.GE);
Defensive patterns

Strategy: type-guard

Validate before calling

if (compType == null || !EnumSet.of(GT, LT, GE, LE, EQ, NE).contains(compType)) {
    throw new IllegalArgumentException("Unsupported compType: " + compType);
}

Type guard

boolean isValidCompType(Expressions.ComparisonType t) {
    return t == GT || t == LT || t == GE || t == LE || t == EQ || t == NE;
}

Try / catch

try {
    res = cmpFn.apply(env, args);
} catch (UnsupportedOperationException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Unknown compType")) {
        res = Expressions.FALSE; // or surface a config error
    } else throw e;
}

Prevention

When it happens

Trigger: Invoking a comparison function (e.g. via a CompareExpression) whose compType field was set to null or an enum value outside {GT,LT,GE,LE,EQ,NE}, typically through programmatic construction or a parser bug.

Common situations: Custom code constructing Expressions.CompareExpression with a null or custom compType; version drift where a new operator isn't mapped in compareTo; deserialization of expressions with invalid operator strings.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java:764

      this.compType = compType;
      this.clazz = clazz;
    }

    @Override
    public String getParamDesc() {
      return "(" + getTypeName(clazz) + "," + getTypeName(clazz) + ")";
    }

    public Boolean compare(T o1, T o2) {
      int res = comparator.compare(o1,o2);
      switch (compType) {
        case GT: return res > 0;
        case LT: return res < 0;
        case GE: return res >= 0;
        case LE: return res <= 0;
        case EQ: return res == 0;
        case NE: return res != 0;
        default: throw new UnsupportedOperationException("Unknown compType: " + compType);
      }
    }

    @Override
    public boolean checkArgs(List<Value> in) {
      if (in.size() != 2) {
        return false;
      }
      if (clazz != null) {
        if (in.get(0) == null || in.get(0).get() == null || !(clazz.isAssignableFrom(in.get(0).get().getClass()))) {
          return false;
        }
        if (in.get(1) == null || in.get(1).get() == null || !(clazz.isAssignableFrom(in.get(1).get().getClass()))) {
          return false;
        }
      }
      return true;
    }

View on GitHub (pinned to 1b7edd19c4)