changeset 60068:2a8310d5265d sealed-types

fixing NPE bug that was provoking several regression tests to fail
author vromero
date Thu, 13 Feb 2020 18:06:24 -0500
parents 4a51efe43d9a
children 2d039936dbb4 146827c3c8e9
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java test/langtools/tools/javac/sealed/SealedCompilationTests.java
diffstat 2 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Thu Feb 13 22:05:34 2020 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Thu Feb 13 18:06:24 2020 -0500
@@ -838,7 +838,9 @@
                                         TreeInfo.declarationFor(tree.sym.outermostClass(), env.toplevel) != null)
                         .collect(List.collector());
                 Set<Type> explicitlySealedSuperTypesInCU = directSuperTypesInSameCU.stream()
-                        .filter(type -> type != tree.sym.type && type.tsym.isSealed()).collect(Collectors.toSet());
+                            .filter(type -> type != tree.sym.type &&
+                                    type.tsym != null &&
+                                    type.tsym.isSealed()).collect(Collectors.toSet());
 
                 boolean anySuperInSameCUIsSealed = !explicitlySealedSuperTypesInCU.isEmpty();
                 if (anySuperInSameCUIsSealed) {
--- a/test/langtools/tools/javac/sealed/SealedCompilationTests.java	Thu Feb 13 22:05:34 2020 +0000
+++ b/test/langtools/tools/javac/sealed/SealedCompilationTests.java	Thu Feb 13 18:06:24 2020 -0500
@@ -84,7 +84,7 @@
             # class Sub implements Sup { }
             """;
         String I2 =
-                """
+            """
             sealed interface Sup # { }
             # class Sub1 implements Sup { }
             # class Sub2 implements Sup { }
@@ -260,6 +260,34 @@
                 sealed class C {}
                 """))
             assertFail("compiler.err.sealed.type.must.have.subtypes", s);
+
+        for (String s : List.of(
+                """
+                sealed interface I {}
+
+                non-sealed interface I2 extends I {}
+                """,
+                """
+                sealed interface I {}
+
+                sealed interface I2 extends I {}
+
+                non-sealed interface I3 extends I2 {}
+                """,
+                """
+                sealed interface I permits I2 {}
+
+                non-sealed interface I2 extends I {}
+                """,
+                """
+                sealed interface I permits I2 {}
+
+                sealed interface I2 extends I permits I3 {}
+
+                non-sealed interface I3 extends I2 {}
+                """
+                ))
+            assertOK(s);
     }
 
     public void testEnumsCantBeSealedOrNonSealed() {