Repository navigation
fix: keep static valueOf after X.null is read - #2119
edusperoni wants to merge 1 commit into
Conversation
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".
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Description
Reading
X.nullon a Java class broke that class's staticvalueOffor the rest of the runtime's life.The bug
X.nullis 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 ownvalueOfwith a function that returns null. On a class whosevalueOfis a static Java method, that replaced the method:valueOfis affected:Integer.valueOf(5)afterInteger.null, and every enum'svalueOf("NAME")after its.null..null.valueOf() === nullin 2016.The fix
X.nullnow returns a separate object that carries the typed-null tag and a non-enumerablevalueOfreturning null. It is created on first read and cached on the class, soX.null === X.nullstill 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.nullis no longerX, andtypeof X.nullis"object"instead of"function".neware no longer reachable throughX.null.A search of
@nativescript/coreand of local plugin sources found no code that relies on either.A JS-extended class's
.nullis still a typed null of its Java base class.Verification
TestArrayOperations, a Proxy static-call spec) fail with them once a spec has readInteger.null.Not changed: assigning
X.nullto aString-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(staticvalueOfonString,Integerand an enum after.nullis read; the class object not accepted as a typed null; identity andvalueOfof the literal; conversion to a Java null; a JS-extended class; a worker). Each spec reads.nullitself, so none depends on suite order.Summary by CodeRabbit
.nullproperties now return a stable typed-null value on repeated access, without changing the class object.nulland resolve using the appropriate Java type, including for JavaScript-extended classes..nullproperty.