Repository navigation
Description
A Clone Graph answer that returns a node whose neighbors list itself is null, rather than a list holding a null element (#725), fails inside the Java and Python checkers, while JavaScript treats the same list as empty and grades the answer as a plain mismatch. Raised by @Wu-1127 in review of #729, which is limited to the null element.
Observed
At fe04f8f plus the change in #729, with a one-case graphNode spec (input [[2,3],[1,3],[1,2]]) and a candidate that builds the triangle and then sets the neighbors of node 2 to null:
| Language | Case result |
|---|---|
| Java | error java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "<local3>.neighbors" is null |
| Python | error TypeError: 'NoneType' object is not iterable (run under CPython; Pyodide was not reachable on my machine) |
| JavaScript | fails as a mismatch: got [[2,3],[],[1,2]], expected [[2,3],[1,3],[1,2]] |
Java was compiled from generateHarness output with javac; JavaScript was run through runBrowserTests in Chromium.
C++ holds neighbors in a std::vector, which cannot be null. C walks numNeighbors entries, so a NULL array with a count of 0 is already an empty list; a NULL array with a nonzero count is a candidate whose own fields disagree, which the harness cannot detect and this issue does not cover.
Cause
- Java,
graphJsonin the Java template,web/compiler-explorer.js:782: bothfor (Node next : cur.neighbors)loops, the one that queues neighbors and the one that builds rows, iterate a null list. - Python,
_graph_to_adjacency,web/runners.js: the queue loop at line 1149 readsgetattr(current, "neighbors", []) or [], but the row building at line 1152 readsby_value[value].neighborswithout theor []. - JavaScript,
graphToAdjacency,web/runners.js:791and:796: both reads fall back with|| [](current.neighbors || []when queueing,byValue.get(value).neighbors || []when building rows), so a null list is an empty one.
Proposed change
Treat a null neighbors list as empty in Java and Python, as JavaScript already does: in Java, read cur.neighbors == null ? List.of() : cur.neighbors in both loops; in Python, add or [] to the row building. A node with no neighbors and a node whose list is null then serialize the same way in all three, and a wrong answer of this shape fails as a mismatch instead of an exception from the checker. Refusing a null list with its own message would also make the three agree, but it would fail an answer that is otherwise correct for a node with no neighbors, which JavaScript accepts today.
Tests: a nullList scenario in tests/browser/graph-clone-identity.test.js for Java, JavaScript and Python, asserting the same mismatch in each.
This builds on #729 and waits for it to merge, since both change the same serializers.
Activity
jserv commentedon Nov 16, 2026
@Urdan0117 Confirmed on
main: bothfor (Node next : cur.neighbors)loops in the JavagraphJson(web/compiler-explorer.js) and the Python row builder inweb/runners.jsiterate a nullneighborslist, while JavaScript treats it as empty. Accepted as scoped, in its own pull request apart from #729: treat a nullneighborslist as empty in Java and Python as JavaScript does, with one test per language. Open the pull request withClose #736.