{"record":{"id":"b620fbe6ba9bf5ac","repo":"stanfordnlp/CoreNLP","slug":"cannot-evaluate-type-typename","errorCode":null,"errorMessage":"Cannot evaluate type: ${typename}","messagePattern":"Cannot evaluate type: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java","lineNumber":377,"sourceCode":"      return result;\n    }\n  }\n\n  /**\n   * A simple implementation of an expression that is represented by a java object of type T\n   *    and which also has a cached Value stored with it\n   * @param <T> type of the expression object\n   */\n  public static class SimpleCachedExpression<T> extends SimpleExpression<T> {\n    Value evaluated;\n    boolean disableCaching = false;\n\n    protected SimpleCachedExpression(String typename, T value, String... tags) {\n      super(typename, value, tags);\n    }\n\n    protected Value doEvaluation(Env env, Object... args) {\n      throw new UnsupportedOperationException(\"Cannot evaluate type: \" + typename);\n    }\n\n    public Value evaluate(Env env, Object... args) {\n      if (args != null) {\n        return doEvaluation(env, args);\n      }\n      if (evaluated == null || disableCaching) {\n        evaluated = doEvaluation(env, args);\n      }\n      return evaluated;\n    }\n\n    public boolean hasValue() {\n      return (evaluated != null);\n    }\n\n    @Override\n    public boolean equals(Object o) {","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java#L359-L395","documentation":"SimpleCachedExpression is the base class for constant/literal expression types (strings, numbers, etc.) in Expressions. Its doEvaluation is deliberately unimplemented: evaluating a cached-type expression directly is unsupported, so it throws UnsupportedOperationException('Cannot evaluate type: <typename>'). Only concrete subclasses that override doEvaluation can be evaluated.","triggerScenarios":"Calling evaluate(env, args) on an Expression whose class is the plain SimpleCachedExpression (or a subclass that does not override doEvaluation), typically reached through Expressions.evaluate or Value lookups on a literal expression type.","commonSituations":"Custom TokensRegex expression extensions that subclass SimpleCachedExpression without overriding doEvaluation; reflection-driven evaluation over expression lists that includes non-evaluable literal nodes.","solutions":["Override doEvaluation in your SimpleCachedExpression subclass to return the appropriate Value.","Use the concrete expression factory methods (Expressions.createExpression etc.) so you get an evaluable type.","Skip or special-case constant/cached nodes when iterating expressions for evaluation.","Check the typename in the message to identify which expression class lacks the override."],"exampleFix":"// before\nclass MyExpr extends Expressions.SimpleCachedExpression<String> {\n  MyExpr(String v) { super(\"MY\", v); }\n}\n// after\nclass MyExpr extends Expressions.SimpleCachedExpression<String> {\n  MyExpr(String v) { super(\"MY\", v); }\n  @Override protected Value doEvaluation(Env env, Object... args) {\n    return new Expressions.PrimitiveValue<>(\"MY\", get());\n  }\n}","handlingStrategy":"try-catch","validationCode":"// Only evaluate expressions whose type is evaluable\nif (expr instanceof Expressions.SimpleCachedExpression\n    && expr.getClass() == Expressions.SimpleCachedExpression.class) {\n  throw new IllegalStateException(\"Refusing to evaluate non-evaluable cached expression\");\n}","typeGuard":"boolean isEvaluable(Expression e) {\n  return !(e.getClass() == Expressions.SimpleCachedExpression.class);\n}","tryCatchPattern":"try {\n  Value v = expr.evaluate(env);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot evaluate type:\")) {\n    logger.warning(\"Skipping non-evaluable expression type: \" + e.getMessage());\n    return null;\n  }\n  throw e;\n}","preventionTips":["Always override doEvaluation when subclassing SimpleCachedExpression.","Use Expressions factory methods instead of instantiating cached types directly.","Skip constant nodes when walking expression trees for evaluation."],"tags":["expressions","unsupported-operation","tokensregex","java"],"backgroundTag":"unsupported-operation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}