stanfordnlp/CoreNLP · error · RuntimeException
Warning: bad pattern "%s" + pattern
Error message
Warning: bad pattern "%s" + pattern
What it means
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.
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
Example fix
// before
throw new RuntimeException("Warning: bad pattern \"%s\"\n" + pattern);
// after
throw new RuntimeException(String.format("Warning: bad pattern \"%s\"%n", pattern)); Defensive patterns
Strategy: try-catch
Validate before calling
// validate pattern tokens against supported kinds before matching
boolean knownPatternElement(Object elem) {
return elem instanceof String || elem instanceof GrammaticalRelation
|| elem instanceof java.util.regex.Pattern;
} Try / catch
try {
boolean ok = graph.matchPatternToVertex(pattern, vertex);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Warning: bad pattern")) {
// log full pattern, skip or re-parse with a corrected grammar
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/3ebe0512a81cf2d7.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/SemanticGraph.java:414
for (Pair<GrammaticalRelation, IndexedWord> pair : children) {
if (pair.first().toString().equals("det"))
continue;
IndexedWord child = pair.second();
String lemma = child.get(CoreAnnotations.LemmaAnnotation.class);
if (lemma.isEmpty()) {
lemma = child.word().toLowerCase();
}
if (lemma.equals(word)) {
match = true;
break;
}
}
if (!match) {
return false;
}
}
} else {
throw new RuntimeException("Warning: bad pattern \"%s\"\n" + pattern);
}
}
return true;
}
// todo [cdm 2013]: Completely RTE-specific methods like this one should be used to a static class of helper methods under RTE
public boolean matchPatternToVertex(String pattern, IndexedWord vertex) {
if (!containsVertex(vertex)) {
throw new IllegalArgumentException();
}
String pat = pattern.replaceAll("<", ",<");
pat = pat.replaceAll(">", ",>");
String[] nodePath = pat.split(",");
for (String s : nodePath) {
if (s.isEmpty()) {
continue;
}
String word = s.substring(1);View on GitHub (pinned to 1b7edd19c4)