RFR: add use site null checks
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Jan 15 09:55:59 UTC 2026
On Thu, 15 Jan 2026 09:50:23 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Adding use site null checks for method invocations. They are added by default but if option: `noUseSiteNullChecks` is passed, the compiler won't generate them
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/NullChecksWriter.java line 204:
>
>> 202: }
>> 203: Type formalArgType = declaredArgTypes.head;
>> 204: if (msym.isVarArgs() && formalArgType == varArgsArg) {
>
> I think this check can misfire. Some types are shared -- e.g. syms.stringType, so you might get `==` in "wrong" places. That said, here `varArgsArg` is an array type, and for that we might always get a fresh instance... so it might work.
>
> It also looks like there might be a potential problem here -- this code runs _after_ varargs translation has occurred. Meaning that for varargs, we only see a javac-created array and we can check the variadic elements.
>
> But again, the plan here would be to disallow `C!...` so this is ok.
Question, now that I read through all the code... I wonder if we could do this more simply:
* take the list of actual arguments
* skip the first P prefix arguments
* drop the last variadic array (if the method is variadic)
* then do a loop and check what remains against the "source-like" formal types
-------------
PR Review Comment: https://git.openjdk.org/valhalla/pull/1910#discussion_r2693704826
More information about the valhalla-dev
mailing list