diff --git a/test/langtools/tools/javac/bang/BangTypesCompilationTests.java b/test/langtools/tools/javac/nullability/NullabilityCompilationTests.java similarity index 99% rename from test/langtools/tools/javac/bang/BangTypesCompilationTests.java rename to test/langtools/tools/javac/nullability/NullabilityCompilationTests.java index dd51c015795..ec7dcb7296f 100644 --- a/test/langtools/tools/javac/bang/BangTypesCompilationTests.java +++ b/test/langtools/tools/javac/nullability/NullabilityCompilationTests.java @@ -22,7 +22,7 @@ */ /** - * BangTypesCompilationTests + * NullabilityCompilationTests * * @test * @enablePreview @@ -33,7 +33,7 @@ * jdk.compiler/com.sun.tools.javac.code * jdk.compiler/com.sun.tools.javac.util * jdk.jdeps/com.sun.tools.classfile - * @run testng/othervm BangTypesCompilationTests + * @run testng/othervm NullabilityCompilationTests */ import java.util.List; import java.util.function.Consumer; @@ -46,11 +46,11 @@ import static org.testng.Assert.assertEquals; @Test -public class BangTypesCompilationTests extends CompilationTestCase { +public class NullabilityCompilationTests extends CompilationTestCase { private static String[] EMPTY_OPTIONS = {}; private static String[] LINT_OPTIONS = { "-Xlint:null" }; - public BangTypesCompilationTests() { + public NullabilityCompilationTests() { setDefaultFilename("Test.java"); } diff --git a/test/langtools/tools/javac/bang/BangTypeParsingTest.java b/test/langtools/tools/javac/nullability/NullabilityParsingTest.java similarity index 65% rename from test/langtools/tools/javac/bang/BangTypeParsingTest.java rename to test/langtools/tools/javac/nullability/NullabilityParsingTest.java index 7cfe3b26648..5af94ca68b4 100644 --- a/test/langtools/tools/javac/bang/BangTypeParsingTest.java +++ b/test/langtools/tools/javac/nullability/NullabilityParsingTest.java @@ -27,61 +27,49 @@ * @test * @enablePreview * @summary Smoke test for parsing of bang types - * @compile BangTypeParsingTest.java + * @compile NullabilityParsingTest.java */ import java.util.function.*; import java.util.*; -class Test { +class NullabilityParsingTest { // fields - Object? o1; Object! o2; // method parameters - void m1(Object? o) { } void m2(Object! o) { } // method returns - Object? m1() { return null; } - Object! m2() { return null; } + Object! m2() { return new Object(); } // locals void testLocals() { - Object? o1; Object! o2; } // generics - field - Consumer<Object?> co1; Consumer<Object!> co2; // generics - method param - void m3(Consumer<Object?> co) { } void m4(Consumer<Object!> co) { } // generics - method return - Consumer<Object?> m3() { return null; } Consumer<Object!> m4() { return null; } // generics - local void testGenericLocals() { - Consumer<Object?> co1; Consumer<Object!> co2; } // lambdas void testLambdas() { - Consumer<Object?> co1 = (Object? co) -> {}; Consumer<Object!> co2 = (Object! co) -> {}; } void testGenericLambdas() { - Consumer<Consumer<Object?>> co1 = (Consumer<Object?> co) -> {}; Consumer<Consumer<Object!>> co2 = (Consumer<Object!> co) -> {}; - Consumer<Function<Object?, Object!>> co3 = (Function<Object?, Object!> co) -> {}; - Consumer<Function<Object!, Object?>> co4 = (Function<Object!, Object?> co) -> {}; - Consumer<Consumer<Consumer<Consumer<Object?>>>> co5 = (Consumer<Consumer<Consumer<Object?>>> co) -> {}; + Consumer<Function<Object!, Object!>> co3 = (Function<Object!, Object!> co) -> {}; Consumer<Consumer<Consumer<Consumer<Object!>>>> co6 = (Consumer<Consumer<Consumer<Object!>>> co) -> {}; } @@ -90,8 +78,8 @@ void testGenericLambdas() { void testTypeTestPatterns(Object o) { switch (o) { case Integer! i -> throw new AssertionError(); - case String? s -> throw new AssertionError(); - default -> throw new AssertionError(); + case String! s -> throw new AssertionError(); + default -> throw new AssertionError(); } } @@ -102,9 +90,6 @@ void genericTypeTestPatterns(A o) { switch (o) { case I<Integer!> i -> { } } - switch (o) { - case I<Integer?> i -> { } - } } sealed interface I2<X> {} @@ -114,9 +99,6 @@ void genericTypeTestPatterns(A2 o) { switch (o) { case I2<I<Integer!>> i -> { } } - switch (o) { - case I2<I<Integer?>> i -> { } - } } sealed interface I3<X> {} @@ -126,9 +108,6 @@ void genericTypeTestPatterns(A3 o) { switch (o) { case I3<I2<I<Integer!>>> i -> { } } - switch (o) { - case I3<I2<I<Integer?>>> i -> { } - } } // record patterns @@ -136,9 +115,6 @@ void genericTypeTestPatterns(A3 o) { record R(A a) { } void genericRecordPatterns(R o) { - switch (o) { - case R?(I<Integer?> i) -> { } - } switch (o) { case R!(I<Integer!> i) -> { } } @@ -147,9 +123,6 @@ void genericRecordPatterns(R o) { record R2(A2 a2) { } void genericRecordPatterns(R2 o) { - switch (o) { - case R2?(I2<I<Integer?>> i) -> { } - } switch (o) { case R2!(I2<I<Integer!>> i) -> { } } @@ -158,9 +131,6 @@ void genericRecordPatterns(R2 o) { record R3(A3 a3) { } void genericRecordPatterns(R3 o) { - switch (o) { - case R3?(I3<I2<I<Integer?>>> i) -> { } - } switch (o) { case R3!(I3<I2<I<Integer!>>> i) -> { } } @@ -169,83 +139,59 @@ void genericRecordPatterns(R3 o) { // instanceof/cast void testInstanceOf(Object o) { - boolean r1 = o instanceof String?; boolean r2 = o instanceof String!; } void testInstanceRecord(R r) { - boolean r1 = r instanceof R(I<Integer?> i); boolean r2 = r instanceof R(I<Integer!> i); } void testCast(Object o) { - String? s1 = (String?)o; String! s2 = (String!)o; } void testGenericCast(A a) { - I<Integer?> i1 = (I<Integer?>)a; I<Integer!> i2 = (I<Integer!>)a; } void testGenericCast2(A a) { - I?<Integer?> i1 = (I?<Integer?>)a; I!<Integer!> i2 = (I!<Integer!>)a; } // arrays - Object?[]![]?[]! oarr; - Function?<Object?[]![]?, Function<Object?[]![]?, Object?[]![]?>>[]![]? garr; - - // patterns and for-each - - void forEachPatterns(List<R> o) { - for (R?(I<Integer?> i) : o) { } - for (R!(I<Integer!> i) : o) { } - } - - void forEachPatterns2(List<R2> o) { - for (R2?(I2<I?<Integer?>> i) : o) { } - for (R2 !(I2<I!<Integer!>> i) : o) { } - } - - void forEachPatterns3(List<R3> o) { - for (R3?(I3?<I2?<I<Integer?>>> i) : o) { } - for (R3!(I3!<I2!<I<Integer!>>> i) : o) { } - } + Object![]![]![]! oarr; + Function!<Object![]![]!, Function<Object![]![]!, Object![]![]!>>[]![]! garr; void mBad1(Object o) { String s1 = o instanceof String ? (String)o : null; - String s2 = o instanceof String? ? (String)o : null; + String s2 = o instanceof String! ? (String)o : null; } void mBad2(Object o) { String s1 = o instanceof String ? "" : null; - String s2 = o instanceof String? ? "" : null; + String s2 = o instanceof String! ? "" : null; } void testPatternRule(Object o) { switch (o) { - case String? s -> { } + case String! s -> { } default -> { } } } void testPatternCol(Object o) { switch (o) { - case String? s: { } + case String! s: { } default: { } } } void testInstanceOfAndInfix1(Object a, boolean b) { - boolean x1 = a instanceof String? && b; boolean x2 = a instanceof String! && b; } void testInstanceOfAndInfix2(Object a, boolean b) { - boolean x1 = a instanceof String? s && b; boolean x2 = a instanceof String! s && b; } } diff --git a/test/langtools/tools/javac/bang/RuntimeNullChecks.java b/test/langtools/tools/javac/nullability/RuntimeNullChecks.java similarity index 100% rename from test/langtools/tools/javac/bang/RuntimeNullChecks.java rename to test/langtools/tools/javac/nullability/RuntimeNullChecks.java