RFR: add use site null checks for fields [v5]

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Jan 19 20:13:03 UTC 2026


On Sat, 17 Jan 2026 01:15:22 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> generate null checks for field use sites depending on a compiler option, see also [1] which did a similar thing for method invocations
>> 
>> [1] https://github.com/openjdk/valhalla/pull/1910
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
> 
>   changes to test

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/NullChecksWriter.java line 176:

> 174:         private boolean isInThisSameCompUnit(Symbol sym) {
> 175:             return env.toplevel.getTypeDecls().stream().anyMatch(tree -> TreeInfo.symbolFor(tree) == outermostType(sym));
> 176:         }

Btw, a cheaper check here could be to get `env.enclClass` and call `outermostClass` on its symbol, then compare it with the `outermostClass` of the accessed field symbol and check if they are the same. It should work well, but it will not handle auxiliary classes well (as an aux class is not "nested" in the toplevel class)

-------------

PR Review Comment: https://git.openjdk.org/valhalla/pull/1926#discussion_r2705957460


More information about the valhalla-dev mailing list