{"record":{"id":"36c4e877fe7acb3a","repo":"stanfordnlp/CoreNLP","slug":"expression-was-not-evaluated","errorCode":null,"errorMessage":"Expression was not evaluated....","messagePattern":"Expression was not evaluated\\.\\.\\.\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java","lineNumber":1210,"sourceCode":"      }\n      return ok;\n    }\n\n    public Set<String> getAttributes() {\n      return value.keySet();\n    }\n\n    public Expression getExpression(String attr) {\n      return value.get(attr);\n    }\n\n    public Value getValue(String attr) {\n      Expression expr = value.get(attr);\n      if (expr == null) return null;\n      if (expr instanceof Value) {\n        return (Value) expr;\n      }\n      throw new UnsupportedOperationException(\"Expression was not evaluated....\");\n    }\n\n    public <T> T get(String attr) {\n      Expression expr = value.get(attr);\n      if (expr == null) return null;\n      if (expr instanceof Value) {\n        return ((Value<T>) expr).get();\n      }\n      throw new UnsupportedOperationException(\"Expression was not evaluated....\");\n    }\n\n    public void set(String attr, Object obj) {\n      if (obj instanceof Expression) {\n        value.put(attr, (Expression) obj);\n      } else {\n        value.put(attr, createValue(null, obj));\n      }\n      evaluated = null;","sourceCodeStart":1192,"sourceCodeEnd":1228,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/types/Expressions.java#L1192-L1228","documentation":"Expressions.MapValue stores unevaluated Expression objects per attribute. getValue(attr) only supports already-evaluated Values; if the stored expression is not a Value instance, it cannot return it and throws UnsupportedOperationException('Expression was not evaluated....').","triggerScenarios":"Calling getValue(attr) on a MapValue produced from expressions that were never evaluated — e.g. reading fields of a composite expression result directly instead of calling evaluate() first, or fetching attributes whose expressions are lazy/deferred.","commonSituations":"Custom code walking TokensRegex expression results and calling getValue() on a nested MapValue before running the evaluation phase, or attributes created by `with`/assignment clauses that weren't evaluated.","solutions":["Call evaluate(env, args) on the expression (or the MapValue's expressions) before calling getValue","Use the get(String attr)/generic accessor path if it handles evaluation, instead of getValue","Check the attribute key: expr==null returns null silently, so a wrong key is not the cause — the key exists but holds an unevaluated Expression","If you own the code, evaluate the nested expression and store the resulting Value back into the map"],"exampleFix":"// before\nValue v = mapValue.getValue(\"key\"); // holds raw Expression\n// after\nValue v = (Value) expression.evaluate(env).get(); // evaluate first, or use the evaluate() API on the parent expression","handlingStrategy":"type-guard","validationCode":"Expression e = mapValue.getExpression(attr); // or via underlying map\nif (e instanceof Value) {\n    Value v = (Value) e;\n} else {\n    e.evaluate(env); // evaluate before getValue\n}","typeGuard":"boolean isEvaluated(Expression e) {\n    return e instanceof Value;\n}","tryCatchPattern":"try {\n    Value v = mapValue.getValue(attr);\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().contains(\"not evaluated\")) {\n        // run the evaluation phase, then retry\n    } else throw e;\n}","preventionTips":["Always run expression.evaluate(env) before reading results via getValue","Use the evaluate() pipeline API rather than poking at intermediate MapValue structures","In custom walkers, check `instanceof Value` before casting expression results"],"tags":["tokensregex","expression-language","unevaluated-expression"],"backgroundTag":"invalid-state-transition","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}