Skip to content

fix: keep static valueOf after X.null is read - #2119

Open
edusperoni wants to merge 1 commit into
mainfrom
fix/null-accessor-keeps-valueof
Open

edusperoni wants to merge 1 commit into
mainfrom
fix/null-accessor-keeps-valueof

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Reading X.null on a Java class broke that class's static valueOf for the rest of the runtime's life.

The bug

X.null is the typed-null literal used to pick an overload or pass a Java null of a given type. Its accessor returned the class constructor itself, after tagging it as a typed null and replacing the constructor's own valueOf with a function that returns null. On a class whose valueOf is a static Java method, that replaced the method:

java.lang.String.valueOf(42);   // "42"
java.lang.String.null;          // any read, anywhere in this runtime
java.lang.String.valueOf(42);   // null, without ever calling Java
  • Every class with a static valueOf is affected: Integer.valueOf(5) after Integer.null, and every enum's valueOf("NAME") after its .null.
  • The tag also made the class object itself convert to a Java null when passed as an argument.
  • It has been this way since the literal gained .null.valueOf() === null in 2016.

The fix

X.null now returns a separate object that carries the typed-null tag and a non-enumerable valueOf returning null. It is created on first read and cached on the class, so X.null === X.null still holds. The constructor is never modified.

Argument conversion and overload resolution read the same tag from the argument as before, so their per-call cost is unchanged.

Behaviour change

  • X.null is no longer X, and typeof X.null is "object" instead of "function".
  • Static methods and new are no longer reachable through X.null.

A search of @nativescript/core and of local plugin sources found no code that relies on either.

A JS-extended class's .null is still a typed null of its Java base class.

Verification

  • On an API 33 phone, six of the seven new specs fail on unfixed main for the reasons above, and two existing specs (TestArrayOperations, a Proxy static-call spec) fail with them once a spec has read Integer.null.
  • With the fix: 1607 specs, 0 failures (main's 1600 plus 7 new). The existing typed-null specs pass unchanged.

Not changed: assigning X.null to a String-typed field or into a Java array element, which do not read the typed-null tag today either.

Does your pull request have unit tests?

Yes: a new suite in testMethodResolutionWithNulls.js (static valueOf on String, Integer and an enum after .null is read; the class object not accepted as a typed null; identity and valueOf of the literal; conversion to a Java null; a JS-extended class; a worker). Each spec reads .null itself, so none depends on suite order.

Summary by CodeRabbit

  • Bug Fixes
    • Java class .null properties now return a stable typed-null value on repeated access, without changing the class object.
    • Typed nulls correctly convert to Java null and resolve using the appropriate Java type, including for JavaScript-extended classes.
    • Standard static methods remain callable after accessing a class’s .null property.

Reading X.null returned the class constructor itself after tagging it
with the null-node private and replacing its own valueOf with a function
that returns null. On a class with a static valueOf that replaced the
Java method for the rest of the runtime: once String.null had been read,
java.lang.String.valueOf(anything) returned null without calling Java,
and Integer.valueOf, Long.valueOf and every enum's valueOf(String)
broke the same way. The tag also made the class object itself convert
to a Java null when passed as an argument.

X.null now returns a separate object that carries the null-node private
and a non-enumerable valueOf returning null. It is created on first read
and cached on the receiver under its own private key, so X.null === X.null
still holds and nothing is shared between isolates. The constructor is
never modified. A JS-extended class reaches the accessor of its Java
base class, so its .null is a typed null of that base class, as before.

The argument converters and overload resolution read the same private
from the argument they always read, so their per-call cost is unchanged.

Behavior change: X.null is no longer X, and typeof X.null is "object"
rather than "function".
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The runtime now returns a cached sentinel object for each Java class .null access. Tests cover sentinel identity, Java-null conversion, method resolution, and worker-local behavior.

Changes: Typed Java nulls

Layer / File(s) Summary
Create and cache typed-null sentinels
test-app/runtime/src/main/cpp/V8StringConstants.h, test-app/runtime/src/main/cpp/V8StringConstants.cpp, test-app/runtime/src/main/cpp/MetadataNode.cpp
The runtime adds a per-isolate private key and uses it to cache a separate sentinel on the receiver. The sentinel carries null-node metadata and a non-enumerable valueOf function.
Validate typed-null interop
test-app/app/src/main/assets/app/tests/testMethodResolutionWithNulls.js, test-app/app/src/main/assets/app/tests/typedNullWorker.js
Tests cover static method calls, sentinel identity, Java-null conversions, overload resolution, and worker behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: nathanwalker

Merge Risk: Minimal · up to 6bb36

This change stops reading X.null from replacing a Java class's static valueOf or making the class itself convert to Java null. The new behavior differs intentionally: X.null is now a separate object rather than the class. The tests cover it, and no concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: keep static valueOf after X.null is read" matches the main change. The PR stops reading X.null from replacing a Java class's static valueOf or turning the class into a Java null. It re…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: keep static valueOf after X.null is read" matches the main change. The PR stops reading X.null from replacing a Java class's static valueOf or turning the class into a Java null. It returns a cached sentinel object for X.null, and the class object is left unchanged. The title states the bug fix and the affected behavior. It uses the conventional fix: prefix and stays short.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7228595 and 6bb36ae.

Files selected for processing: 5

  • test-app/app/src/main/assets/app/tests/testMethodResolutionWithNulls.js
  • test-app/app/src/main/assets/app/tests/typedNullWorker.js
  • test-app/runtime/src/main/cpp/MetadataNode.cpp
  • test-app/runtime/src/main/cpp/V8StringConstants.cpp
  • test-app/runtime/src/main/cpp/V8StringConstants.h

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant