Fwd: Suggestion regarding Null State Analysis in Project Valhalla
Brian Goetz
brian.goetz at oracle.com
Thu Jun 12 11:55:19 UTC 2025
Received on the -comments list.
Begin forwarded message:
From: Abdurasul Abduraimov <abdurasulabduraimov22 at gmail.com<mailto:abdurasulabduraimov22 at gmail.com>>
Subject: Suggestion regarding Null State Analysis in Project Valhalla
Date: June 12, 2025 at 1:06:49 AM EDT
To: valhalla-spec-comments at openjdk.org<mailto:valhalla-spec-comments at openjdk.org>
Dear Team,
I am a big fan of Java and I’m eagerly awaiting the release of Project Valhalla. I watched the Valhalla session from IntelliJ IDEA Conf 2025 (Day 1), where Rémi Forax discussed the "Null State Analysis" feature. As he explained, the system defines three null states:
1. Null-restricted: Integer! or String!
2. Nullable: Integer? or String?
3. Unspecified: Integer or String (with no warning)
I understand that due to Java’s large amount of legacy code, introducing nullable and non-nullable types (as in Kotlin) is challenging, and the team is prioritizing backward compatibility.
However, I’d like to propose an idea:
What if the Unspecified state also emitted a warning? This way, all types would continue to be effectively nullable (as they are today), but developers upgrading to future Java versions (where Valhalla is finalized) would be encouraged to explicitly annotate their types. They could mark types as not-null where appropriate, or accept the nullable default, making their intentions clear.
This would parallel Kotlin’s philosophy, but in an inverse way:
* In Kotlin: all types are not-null by default, nullable types must be explicitly declared.
* In Java (with this proposal): all types would be nullable by default, but not-null types would be explicitly declared — with the added benefit of a warning to help modernize existing code.
I know it’s a bit unusual, but I believe this approach could strike a balance between safety, clarity, and backward compatibility.
Thank you for your great work on Java!
Best regards,
Abdurasul Abduraimov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-experts/attachments/20250612/f0c414f9/attachment-0001.htm>
More information about the valhalla-spec-experts
mailing list