RFR: Remove redundant null checks [v5]
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Jan 23 10:24:32 UTC 2026
On Fri, 23 Jan 2026 02:27:07 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> some of the null checks javac generates are redundant and can be removed
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>
> adding more tests
Looks a good start. We could stop here, or we could probably think a bit more about how to propagate the info as to whether some sub-expression has already been validated to be strict -- which will allow us to omit use site checks in more cases.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/NullChecksWriter.java line 271:
> 269: hasNonNullArgs(msym) &&
> 270: canBeOverriden) {
> 271: tree.args = newArgs(msym, tree.args);
The `newArgs` check should somehow be recursive -- e.g. one or more arguments could be already known to be nulll restricted, so we don't really need a use site check. E.g. there's many ingredients here:
1. Can we trust the signature of the method we're calling?
2. Can we trust the static nullness status of any of the method params?
An extra use site check should only be added if neither (1) or (2) hold
-------------
PR Review: https://git.openjdk.org/valhalla/pull/1947#pullrequestreview-3696821451
PR Review Comment: https://git.openjdk.org/valhalla/pull/1947#discussion_r2720606124
More information about the valhalla-dev
mailing list