Repository navigation
Read a null graph neighbors list as empty - #870
Merged
Merged
Conversation
jserv
reviewed
Nov 26, 2026
jserv
reviewed
Nov 26, 2026
jserv
reviewed
Nov 26, 2026
A Clone Graph answer whose node has a null neighbors list crashed the Java and Python checkers, and C read a NULL neighbors array with a positive numNeighbors through a null pointer, while JavaScript read the list as empty. Read a null list as empty in every serializer, with one helper in Java and in Python so the walk and the row builder agree, and pin it with a nullList scenario for C, Java, JavaScript and Python. Close sysprog21#736 Change-Id: Ia982451ca85901471c0c1dc9ea83f5e1d8fb30ed
Urdan0117
force-pushed
the
null-neighbors-list
branch
from
November 26, 2026 09:13
a91a09a to
387ae64
Compare
ColtenOuO
approved these changes
Nov 26, 2026
Contributor
|
Thank @Urdan0117 for contributing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and behavior
A Clone Graph answer whose node has a null neighbors list crashed the Java and Python checkers (NullPointerException, TypeError), and in C a NULL neighbors array with a positive numNeighbors was read through a null pointer, while JavaScript read the list as empty and graded the answer as a mismatch. After this change all four read a null list as empty and report the same mismatch: got [[2,3],[],[1,2]], expected [[2,3],[1,3],[1,2]].
Approach
Each serializer reads the list through one place, so the walk and the row builder cannot drift apart again: Java uses a neighborsOf helper that returns Collections.emptyList() for a null list (Java 8 syntax, as the harness requires), Python uses _graph_neighbors, which reads getattr(node, "neighbors", None) or [] so a missing attribute is empty too, and C guards the walk with cur->neighbors && j < cur->numNeighbors and takes a degree of 0 for a NULL array in the row builder. A nullList scenario in tests/browser/graph-clone-identity.test.js pins it for C and Java in the toolchain suite and for JavaScript and Python in the browser suite; the C case keeps numNeighbors at 2 so it reaches the guard. C++ is left out because its neighbors vector cannot be null.
Validation
On Ubuntu (WSL), Node.js 22.23.3: node --test tests/browser/graph-clone-identity.test.js passes 50 of 50, including the new nullList case for C, Java, JavaScript and Python (Pyodide). With web/compiler-explorer.js and web/runners.js taken from main, the JavaScript case still passes and the other three fail: C crashes reading the NULL array, Python reports "TypeError: 'NoneType' object is not iterable", and Java reports 'java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because ".neighbors" is null'. javac --release 8 accepts Collections.emptyList() and rejects List.of(). ./scripts/test.sh passes; not run: shellcheck, actionlint, desktop clippy and tests.
Close #736