{"record":{"id":"1aa19371baf05044","repo":"stanfordnlp/CoreNLP","slug":"error-extracting-annotation-from-te","errorCode":null,"errorMessage":"Error extracting annotation from ${te}","messagePattern":"Error extracting annotation from (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/ling/tokensregex/CoreMapExpressionExtractor.java","lineNumber":528,"sourceCode":"  private void annotateExpressions(CoreMap annotation, List<T> expressions) {\n    // TODO: Logging can be excessive\n    List<T> toDiscard = new ArrayList<>();\n    for (T te : expressions) {\n      // Add attributes and all\n      if (te.annotation == null) {\n        try {\n          boolean extractOkay = te.extractAnnotation(env, annotation);\n          if (verbose && extractOkay) {\n            log.info(\"annotateExpressions() matched \" + te + \" from \" + annotation);\n          }\n          if (!extractOkay) {\n            // Things didn't turn out so well\n            toDiscard.add(te);\n            log.warn(\"Error extracting annotation from \" + te /*+ \", \" + te.getExtractErrorMessage() */);\n          }\n        } catch (Exception ex) {\n          if (verbose) {\n            log.warn(\"Error extracting annotation from \" + te);\n            log.warn(ex);\n          }\n        }\n      }\n    }\n    expressions.removeAll(toDiscard);\n  }\n\n  private void annotateExpressions(List<? extends CoreMap> chunks, List<T> expressions) {\n    // TODO: Logging can be excessive\n    List<T> toDiscard = new ArrayList<>();\n    for (T te : expressions) {\n      // Add attributes and all\n      try {\n        boolean extractOkay = te.extractAnnotation(env, chunks);\n        if (verbose && extractOkay) {\n          log.info(\"annotateExpressions() matched \" + te + \" from \" + chunks);\n        }","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/CoreMapExpressionExtractor.java#L510-L546","documentation":"CoreMapExpressionExtractor.annotateExpressions runs TokensRegex extraction over expressions. When an expression fails to extract (a rule match produced nothing usable, or an exception was thrown), the expression is discarded and a warning naming the offending CoreMap is logged. Extraction continues with remaining expressions.","triggerScenarios":"applyCompositeRule/extractExpressions encountering an expression where a rule match fails or a sub-expression throws; exceptions are logged (with the same message) only when verbose=true.","commonSituations":"Custom TokensRegex rules with patterns that don't match the actual annotation structure; rules referencing missing annotation keys; malformed rule files producing null results.","solutions":["Enable verbose mode to also see the underlying exception for failed expressions.","Inspect the failing expression (te) and the rule that processed it; validate the pattern against the actual CoreMap annotations.","Fix or guard the rule (e.g. check required annotations exist) so extraction succeeds or skips intentionally.","Test rules incrementally with TokensRegex debugging tools."],"exampleFix":"// before\nprops.setProperty(\"verbose\", \"false\"); // root exception hidden\n// after\nprops.setProperty(\"verbose\", \"true\"); // logs the ex for the failing expression","handlingStrategy":"try-catch","validationCode":"// verify required annotations exist before extraction\nfor (CoreMap te : expressions) {\n  if (te.get(CoreAnnotations.TokensAnnotation.class) == null) {\n    throw new IllegalStateException(\"expression missing tokens: \" + te);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  extractor.extractExpressions(doc);\n} catch (Exception ex) {\n  log.warn(\"expression extraction failed for document\", ex);\n  // continue with un-enriched annotations\n}","preventionTips":["Run extraction with verbose=true during development.","Unit-test TokensRegex rules against representative CoreMaps.","Keep rule files syntax-validated in CI."],"tags":["java","tokensregex","extraction","parsing"],"backgroundTag":"unexpected-response-shape","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"}