hg: valhalla/valhalla: [lworld] Where statically discernible, javac should reject null assignments to, null casts to and null comparisons with value instances.

Srikanth srikanth.adayapalam at oracle.com
Tue Feb 27 08:25:00 UTC 2018



On Tuesday 27 February 2018 01:38 PM, srikanth.adayapalam at oracle.com wrote:
> Changeset: 605a5a1da9fe
> Author:    sadayapalam
> Date:      2018-02-27 13:34 +0530
> URL:       http://hg.openjdk.java.net/valhalla/valhalla/rev/605a5a1da9fe
>
> [lworld] Where statically discernible, javac should reject null assignments to, null casts to and null comparisons with value instances.

This change set aligns javac's behavior with what is outlined in 
http://mail.openjdk.java.net/pipermail/valhalla-dev/2018-February/003870.html

In particular,

ValueType v = null;  // error: ValueType is not nullable
v = (ValueType) null;  // (ditto)
if (v != null) {}  // (ditto)

Assignment of, casting of or comparison of nulls with/to value instances 
would be rejected by javac where it can be statically determined to be 
the case.

I have raised a follow up ticket: 
https://bugs.openjdk.java.net/browse/JDK-8198748
for injection of null checks at casts (and other contexts?). This I will 
take up after fully
understanding the issue.

Thanks!
Srikanth

>
> ! src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
> ! src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
> ! src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
> - test/langtools/tools/javac/diags/examples/IllegalNullAssignmentToFlattenableValue.java
> ! test/langtools/tools/javac/valhalla/lworld-values/CheckFlattenableFlagFromClass.out
> ! test/langtools/tools/javac/valhalla/lworld-values/CheckMultiDimensionalArrayStore.out
> ! test/langtools/tools/javac/valhalla/lworld-values/CheckNullAssign.java
> ! test/langtools/tools/javac/valhalla/lworld-values/CheckNullCastable.java
> ! test/langtools/tools/javac/valhalla/lworld-values/CheckNullCastable.out
> ! test/langtools/tools/javac/valhalla/lworld-values/FlattenableNegativeTest.out
>



More information about the valhalla-dev mailing list