RFR: 8340125: [lw5] null checks are not being generated for method invocations and array writes [v2]
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Sep 25 15:25:31 UTC 2024
On Wed, 25 Sep 2024 15:21:39 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> javac is not generating null checks for runtime execution for method invocations and array writes
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>
> addressing review comments
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java line 522:
> 520: tree.vartype = translate(tree.vartype, null);
> 521: if (tree.init != null) {
> 522: if (types.isNonNullable(tree.type) && !types.isNonNullable(tree.init.type)) {
I see why you did this. The synthetic casts are added by `TransTypes` in the various visitor methods. This makes sense because the casts are only required for method calls and field accesses.
My feeling is that most of this remains true also for null checks. E.g. you need to insert a check when you are translating a _variable_ (field, local, method parameter), or a _method call_ - in these cases there might be some nullness markers (on the variable, or on the method return) that should be taken into account, and compared with the "expected" nullness. If a "nullness" mismatch is found, a null-check should be inserted.
So I wonder if the main `translate` method should go from this:
translate(expr, expectedErasedType)
To this:
translate(expr, expectedErasedType, expectedNullness)
And the conversions "pushed" down in the visitor, in a similar way as what we do today for synthetic casts.
-------------
PR Review Comment: https://git.openjdk.org/valhalla/pull/1251#discussion_r1775443714
More information about the valhalla-dev
mailing list