semgrex / tregex bugs
Author: AngledLuffaCreated Sep 28, 2026Updated Sep 28, 2026
Another bug list from setting Claude loose on our codebase.
Again, to emphasize: posting this bug is not a request for a long list of LLM generated PRs.
Suspected bugs in semgraph/semgrex/ssurgeon and trees/tregex/tsurgeon
These turned up while documenting these packages for javadoc. None of them are fixed; the javadoc changes don't change behaviour.
Line numbers are for the files in semgrex-tregex-javadoc.zip (they include extra doc lines), so go by the method name.
[checked] means I read the code and confirmed it; the other entries are as the reviewing agents described them.
(doc) means the new javadoc describes the current, buggy behaviour. If you fix the bug, update that doc too.
Ssurgeon
- [checked] KillAllIncomingEdges.evaluate:
success = success || sg.removeEdge(edge)short-circuits. After the first removal,removeEdgeis never called again, so only one incoming edge is removed. - [checked] KillNonRootedNodes.evaluate: same pattern,
changed = changed || sg.removeVertex(node), so only the first unrooted node is removed. - [checked] killNonRooted command name: the Ssurgeon docs call the command
killNonRootedNodes, butKillNonRootedNodes.LABELis"killNonRooted", so the documented name doesn't parse. - [checked] Ssurgeon.assemblePredFromXML:
return andPred/return orPredare inside the loop over children, so only the first child predicate is ever used. - [checked] SsurgOrPred.toString: writes
(ssurg-andinstead of(ssurg-or. - [checked] Ssurgeon resource loading (around line 988): the loop over
resourceNodesreadspatternNodes.item(i). - [checked] CombineMWT.evaluate: computes
changedand then always returnsfalse. - [checked] AddEdge (doc): the 4-argument constructor passes
0.0instead ofweight, so the weight is always dropped, including throughcreateEngAddEdge(..., weight). - [checked] SsurgeonPattern.execute:
break nextMatchabandons all remaining matches when two names bind the same node. The comment says only that match should be dropped, which would becontinue nextMatch. - Ssurgeon XML round trip (createPatternXMLDoc):
- The writer puts every edit as an
<edit>inside one<edit-list>, but the reader treats each<edit-list>as a single edit. - The
semgrex-graphelement is built but never appended to the pattern element. - The language isn't written.
- The writer puts every edit as an
- Ssurgeon.expandFromPatterns: the result of
removeDuplicatesis discarded. - Ssurgeon.main:
argIndex += 2on top of the loop's++argIndexskips an argument after each flag's value. - Ssurgeon, updateMorphoFeatures (less certain): only one value is kept, so repeating
-updateMorphoFeatures, as in the class doc's example, keeps only the last one. - ReattachNamedEdge (doc): checks for an existing edge between the old endpoints rather than the new gov/dep, so its "reuse an existing edge" never happens and duplicates can be created.
- RemoveEdge (doc):
- Leaving out
-govor-depthrows a NullPointerException, although the docs say that means "any". Only a literal**WILDNODE**works. getRelationNamethrows a NullPointerException without-reln.
- Leaving out
- DeleteLeaf: deleting a root leaf leaves it in the graph's roots. Unlike
DeleteGraphFromNode, it never callsresetRoots(). - SplitWord:
headIndexis never range-checked, so a bad value throws only after the other nodes have already been renumbered. - SsurgTestManager (doc): an unregistered id throws a NullPointerException instead of
SsurgeonRuntimeException.
Semgrex / SemanticGraph
- SemanticGraphUtils.semgrexFromGraph with useTag:
str = "tag: " + o.tag()should use+=. As written it produces invalid patterns liketag: NN}. - SemanticGraphUtils.semgrexFromGraphHelper: a revisited node is referred to by its raw
word(), not the name it got on the first visit. - SemanticGraphUtils.diffEdges: the second loop iterates
edges1instead ofedges1Cache, so matching isn't one-to-one. - SemanticGraphUtils.isTree: marks nodes visited when dequeued rather than when enqueued. A DAG such as root→A, root→B, A→C, B→C returns true.
- SemanticGraphUtils.enRepairEdges: modifies edges while iterating
sg.edgeIterable(), which is likely to throwConcurrentModificationException. - SemgrexPattern.main, CoNLL-U output: the highlight sets accumulate across matches, so a sentence with k matches gets k highlight lines, each including the earlier matches' nodes.
- SemgrexPattern class doc: the example
[<subj {} | <agent {}] & @ {}uses&, which the parser now rejects. - SemanticGraph.makeSoftCopy: the old doc said comments are not copied, but the code copies them. The doc now matches the code; check which one you intended.
- SemanticGraph.matchPatternToVertex: the exception message contains an unformatted
%s. - SemanticGraph.getVerticesWithoutParents (private): its doc describes a fallback that the code doesn't implement.
- SemanticGraphFormatter, multi-line mode: a dependent that was already printed produces
reln>with nothing after it. - Alignment:
toString(String)compares format strings with==.makeFromIndexArraystarts at index 0, while word indices start at 1. It appears to be unused.
Tregex / Tsurgeon and the GUI
- [checked] TregexPattern.main
-extractFile: passes[0](the code file) as the tree file too; it should be[1]. The line-split regex\n|\r|\n\ralso turns CRLF input into empty entries. - Macros.readMacros(filename, encoding): never closes its
FileInputStream. - gui/FileTreeModel:
DEFAULT_NEGRA_ENCODING = " ISO-8859-1"has a leading space. - gui/Preferences:
- Tree reader factories and head finders are saved by
getSimpleName(), but the lookup expects other strings, so some saved settings come back as defaults. - An unknown head finder returns null, and
TregexGUIthen dereferences it.
- Tree reader factories and head finders are saved by
- gui/ScrollableTreeJPanel:
- Matched-part coordinates accumulate on every repaint, so prev/next cycles through duplicates.
- The yield and diff rows aren't drawn when the root itself is matched.
- gui/TreeFromFile: checks
instanceof HasIndexbut casts toCoreLabel. - gui/MatchesPanel:
- In show-only-matched-portion mode, the
breakexits only the inner loop. - With Tdiff on, it can throw a NullPointerException when
matchedPartsis null.
- In show-only-matched-portion mode, the
- gui/InputPanel.runScript: an early
returnafter a Tregex compile error leaves the buttons stuck: Cancel stays enabled, and Run script, Search and Browse stay disabled.
Source: stanfordnlp/CoreNLP