Skip to content

Read a null graph neighbors list as empty - #870

Merged
jserv merged 1 commit into
sysprog21:mainfrom
Urdan0117:null-neighbors-list
Nov 26, 2026
Merged

jserv merged 1 commit into
sysprog21:mainfrom
Urdan0117:null-neighbors-list

Conversation

@Urdan0117

@Urdan0117 Urdan0117 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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

cubic-dev-ai[bot]

This comment was marked as resolved.

Comment thread web/compiler-explorer.js Resolved
Comment thread web/runners.js Resolved
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
@github-actions github-actions Bot added ready for maintainer review The pull request ready for maintainer review. area: frontend labels Nov 26, 2026
@github-actions github-actions Bot removed the ready for maintainer review The pull request ready for maintainer review. label Nov 26, 2026
@jserv
jserv merged commit 66ae508 into sysprog21:main Nov 26, 2026
18 checks passed
@jserv

jserv commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Thank @Urdan0117 for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java and Python graph clone checks crash on a null neighbors list

3 participants