Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#1523·CoreNLP

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, removeEdge is 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, but KillNonRootedNodes.LABEL is "killNonRooted", so the documented name doesn't parse.
  • [checked] Ssurgeon.assemblePredFromXML: return andPred / return orPred are inside the loop over children, so only the first child predicate is ever used.
  • [checked] SsurgOrPred.toString: writes (ssurg-and instead of (ssurg-or.
  • [checked] Ssurgeon resource loading (around line 988): the loop over resourceNodes reads patternNodes.item(i).
  • [checked] CombineMWT.evaluate: computes changed and then always returns false.
  • [checked] AddEdge (doc): the 4-argument constructor passes 0.0 instead of weight, so the weight is always dropped, including through createEngAddEdge(..., weight).
  • [checked] SsurgeonPattern.execute: break nextMatch abandons all remaining matches when two names bind the same node. The comment says only that match should be dropped, which would be continue 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-graph element is built but never appended to the pattern element.
    • The language isn't written.
  • Ssurgeon.expandFromPatterns: the result of removeDuplicates is discarded.
  • Ssurgeon.main: argIndex += 2 on top of the loop's ++argIndex skips 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 -gov or -dep throws a NullPointerException, although the docs say that means "any". Only a literal **WILDNODE** works.
    • getRelationName throws a NullPointerException without -reln.
  • DeleteLeaf: deleting a root leaf leaves it in the graph's roots. Unlike DeleteGraphFromNode, it never calls resetRoots().
  • SplitWord: headIndex is 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 like tag: 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 edges1 instead of edges1Cache, 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 throw ConcurrentModificationException.
  • 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 ==.
    • makeFromIndexArray starts 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\r also 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 TregexGUI then dereferences it.
  • 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 HasIndex but casts to CoreLabel.
  • gui/MatchesPanel:
    • In show-only-matched-portion mode, the break exits only the inner loop.
    • With Tdiff on, it can throw a NullPointerException when matchedParts is null.
  • gui/InputPanel.runScript: an early return after a Tregex compile error leaves the buttons stuck: Cancel stays enabled, and Run script, Search and Browse stay disabled.

Source: stanfordnlp/CoreNLP

View original on GitHubView discussion on GitHub