{"record":{"id":"3ebe0512a81cf2d7","repo":"stanfordnlp/CoreNLP","slug":"warning-bad-pattern-s-pattern","errorCode":null,"errorMessage":"Warning: bad pattern \"%s\"\n + pattern","messagePattern":"Warning: bad pattern \"(.+?)\"\n \\+ pattern","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/SemanticGraph.java","lineNumber":414,"sourceCode":"          for (Pair<GrammaticalRelation, IndexedWord> pair : children) {\n            if (pair.first().toString().equals(\"det\"))\n              continue;\n            IndexedWord child = pair.second();\n            String lemma = child.get(CoreAnnotations.LemmaAnnotation.class);\n            if (lemma.isEmpty()) {\n              lemma = child.word().toLowerCase();\n            }\n            if (lemma.equals(word)) {\n              match = true;\n              break;\n            }\n          }\n          if (!match) {\n            return false;\n          }\n        }\n      } else {\n        throw new RuntimeException(\"Warning: bad pattern \\\"%s\\\"\\n\" + pattern);\n      }\n    }\n    return true;\n  }\n\n  // todo [cdm 2013]: Completely RTE-specific methods like this one should be used to a static class of helper methods under RTE\n  public boolean matchPatternToVertex(String pattern, IndexedWord vertex) {\n    if (!containsVertex(vertex)) {\n      throw new IllegalArgumentException();\n    }\n    String pat = pattern.replaceAll(\"<\", \",<\");\n    pat = pat.replaceAll(\">\", \",>\");\n    String[] nodePath = pat.split(\",\");\n    for (String s : nodePath) {\n      if (s.isEmpty()) {\n        continue;\n      }\n      String word = s.substring(1);","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/SemanticGraph.java#L396-L432","documentation":"SemanticGraph.matchPatternToVertex walks a pattern string and matches it against a vertex's relations/children. When a pattern element's type is not one of the recognized kinds (e.g. a relation string that is neither a wildcard nor a valid pattern token), it throws a RuntimeException declaring the pattern bad. The message itself contains a bug: \"Warning: bad pattern \\\"%s\\\"\\n\" + pattern is concatenated, not formatted, so %s is printed literally.","triggerScenarios":"Calling matchPatternToVertex (or public wrappers that evaluate a pattern against a SemanticGraph) with a pattern string containing an unrecognized element type in the branch reached at line 414 — e.g. a pattern token that is not a GrammaticalRelation, regex, or one of the supported node/relation specifiers.","commonSituations":"Typos in hand-written tregex/semgrex-style patterns; copying patterns from docs of a different library version where the token grammar changed; RTE-era helper code encountering a pattern element class it does not handle.","solutions":["Print/correct the pattern string and fix the offending token (the raw pattern is appended after the literal %s)","Verify the pattern syntax against the version of the library in use; patterns for other matchers (tregex) may not be valid here","If a custom pattern element type is passed, convert it to a supported representation before calling","Upgrade/patch the message to use String.format if the literal %s makes debugging hard"],"exampleFix":"// before\nthrow new RuntimeException(\"Warning: bad pattern \\\"%s\\\"\\n\" + pattern);\n// after\nthrow new RuntimeException(String.format(\"Warning: bad pattern \\\"%s\\\"%n\", pattern));","handlingStrategy":"try-catch","validationCode":"// validate pattern tokens against supported kinds before matching\nboolean knownPatternElement(Object elem) {\n  return elem instanceof String || elem instanceof GrammaticalRelation\n      || elem instanceof java.util.regex.Pattern;\n}","typeGuard":null,"tryCatchPattern":"try {\n  boolean ok = graph.matchPatternToVertex(pattern, vertex);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Warning: bad pattern\")) {\n    // log full pattern, skip or re-parse with a corrected grammar\n  } else throw e;\n}","preventionTips":["Validate pattern syntax against the semgrex/RTE grammar of your exact library version","Print the raw pattern (appended at the end of the message) when debugging","Do not reuse tregex patterns where semgrex patterns are expected","Add unit tests for each pattern form your app generates"],"tags":["pattern-matching","semgrex","grammar","rte"],"backgroundTag":"invalid-regex-pattern","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"}