changeset 59837:2ed7a5ed4b7f

8238735: NPE compiling lambda expression within conditional expression Summary: The fix saves result type from the first pass through the Attr.visitLambda and returns it after recovery pass to avoid NPE caused by exposure of Type.recoveryType Reviewed-by: mcimadamore
author asotona
date Wed, 17 Jun 2020 13:18:19 +0200
parents 4c77befd9898
children 8c27acf92bf2
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java test/langtools/tools/javac/8238735/T8238735.java test/langtools/tools/javac/8238735/T8238735.out
diffstat 3 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jun 17 07:40:11 2020 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jun 17 13:18:19 2020 +0200
@@ -3040,7 +3040,14 @@
         } finally {
             localEnv.info.scope.leave();
             if (needsRecovery) {
-                attribTree(that, env, recoveryInfo);
+                Type prevResult = result;
+                try {
+                    attribTree(that, env, recoveryInfo);
+                } finally {
+                    if (result == Type.recoveryType) {
+                        result = prevResult;
+                    }
+                }
             }
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/8238735/T8238735.java	Wed Jun 17 13:18:19 2020 +0200
@@ -0,0 +1,13 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8238735
+ * @summary javac should fail without throwing NPE
+ * @compile/fail/ref=T8238735.out -XDrawDiagnostics T8238735.java
+ */
+
+class T8238735 {
+     public static void main(String[] args) {
+        boolean first = true;
+        first = first ? false : (boolean)(() -> false) ;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/8238735/T8238735.out	Wed Jun 17 13:18:19 2020 +0200
@@ -0,0 +1,2 @@
+T8238735.java:11:43: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf: boolean)
+1 error