changeset 3267:2568113d414c

Fix: Ensure that comparison of nulls to value instances is disallowed Contributed-by: srikanth.adayapalam@oracle.com
author mcimadamore
date Fri, 04 Dec 2015 19:24:04 +0000
parents 358b7a32d810
children 572d8ea3ca59
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java test/tools/javac/valhalla/values/CheckNullAssign.java test/tools/javac/valhalla/values/CheckNullAssign.out
diffstat 3 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Thu Dec 03 12:15:04 2015 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Fri Dec 04 19:24:04 2015 +0000
@@ -1777,7 +1777,7 @@
 
             @Override
             public Boolean visitClassType(ClassType t, Type s) {
-                if (s.hasTag(ERROR) || s.hasTag(BOT) || s.hasTag(TypeTag.ANY_BOUND))
+                if (s.hasTag(ERROR) || s.hasTag(BOT) && !t.isValue() || s.hasTag(TypeTag.ANY_BOUND))
                     return true;
 
                 if (s.hasTag(TypeTag.VAL_BOUND)) {
--- a/test/tools/javac/valhalla/values/CheckNullAssign.java	Thu Dec 03 12:15:04 2015 +0000
+++ b/test/tools/javac/valhalla/values/CheckNullAssign.java	Fri Dec 04 19:24:04 2015 +0000
@@ -7,8 +7,10 @@
 
 final __ByValue class CheckNullAssign {
     CheckNullAssign foo(CheckNullAssign cna) {
+        // All of the below involve subtype/assignability checks and should be rejected.
         cna = null;
         foo(null);
+        if (null instanceof CheckNullAssign) {}
         return null;
     }
 }
--- a/test/tools/javac/valhalla/values/CheckNullAssign.out	Thu Dec 03 12:15:04 2015 +0000
+++ b/test/tools/javac/valhalla/values/CheckNullAssign.out	Fri Dec 04 19:24:04 2015 +0000
@@ -1,4 +1,5 @@
-CheckNullAssign.java:10:15: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, CheckNullAssign)
-CheckNullAssign.java:11:9: compiler.err.cant.apply.symbol: kindname.method, foo, CheckNullAssign, compiler.misc.type.null, kindname.class, CheckNullAssign, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: compiler.misc.type.null, CheckNullAssign))
-CheckNullAssign.java:12:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, CheckNullAssign)
-3 errors
+CheckNullAssign.java:11:15: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, CheckNullAssign)
+CheckNullAssign.java:12:9: compiler.err.cant.apply.symbol: kindname.method, foo, CheckNullAssign, compiler.misc.type.null, kindname.class, CheckNullAssign, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: compiler.misc.type.null, CheckNullAssign))
+CheckNullAssign.java:13:13: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, CheckNullAssign)
+CheckNullAssign.java:14:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, CheckNullAssign)
+4 errors