RFR: fixing bug in null checks generation [v2]
Jan Lahoda
jlahoda at openjdk.org
Mon Jan 26 18:06:20 UTC 2026
On Mon, 26 Jan 2026 16:43:35 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Javac is generating erroneous null checks for code like, test case provided by Jan:
>>
>>
>> public class Main {
>> public String g() {
>> return Other.str = "";
>> }
>> }
>> class Other {
>> public static String! str = "";
>> }
>>
>> so there is no point in generating null checks on the left side of an assignment statement. So the proposal is to use a switch to indicate when null checks shouldn't be generated.
>>
>> TIA
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>
> jan's proposal
The change, as such, looks OK to me, but it would be good to add the test for the problem as well. (I know JShell tests will fail, but it is better to have a test closer to the javac code. Maybe something like:
diff --git a/test/langtools/tools/javac/nullability/RuntimeNullChecks.java b/test/langtools/tools/javac/nullability/RuntimeNullChecks.java
index c8a9ce5d67f..20f7bfcb856 100644
--- a/test/langtools/tools/javac/nullability/RuntimeNullChecks.java
+++ b/test/langtools/tools/javac/nullability/RuntimeNullChecks.java
@@ -310,6 +310,20 @@ public static void main(String... args) {
test.isSystemProperty("1", "2", "3", null);
}
}
+ """,
+ //should not crash javac:
+ """
+ class Test {
+ static String get() {
+ return Other.str = "";
+ }
+ public static void main(String... args) {
+ get();
+ }
+ }
+ class Other {
+ public static String! str = "";
+ }
"""
}) {
System.err.println("executing test " + i++);
?
-------------
PR Comment: https://git.openjdk.org/valhalla/pull/1972#issuecomment-3800936643
More information about the valhalla-dev
mailing list