changeset 48848:18b28297b5ed nestmates

8197402: [Nestmates] Update javac tests that assume existence of synthetic nested classes for constructor access Reviewed-by: dholmes
author mcimadamore
date Tue, 13 Feb 2018 00:03:02 -0500
parents 28145af98042
children b7e59987f688
files test/langtools/tools/javac/6917288/GraphicalInstallerTest.java test/langtools/tools/javac/6917288/T6917288.java test/langtools/tools/javac/7199823/InnerClassCannotBeVerified.java test/langtools/tools/javac/classfiles/attributes/SourceFile/SyntheticClassTest.java test/langtools/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateInnerClassMembersTest.java test/langtools/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateSiblingsTest.java test/langtools/tools/javac/classfiles/attributes/Synthetic/BridgeMethodsForLambdaTest.java test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesInInnerClassTest.java test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesInInnerEnumTest.java test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTest.java test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java test/langtools/tools/javac/nativeHeaders/NativeHeaderTest.java test/langtools/tools/javac/processing/model/completionfailure/NoAbortForBadClassFile.java
diffstat 13 files changed, 149 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/test/langtools/tools/javac/6917288/GraphicalInstallerTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/6917288/GraphicalInstallerTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -47,7 +47,6 @@
         }
 
         check(classes,
-            "GraphicalInstaller$1.class",
             "GraphicalInstaller$1X$1.class",
             "GraphicalInstaller$1X.class",
             "GraphicalInstaller$BackgroundInstaller.class",
--- a/test/langtools/tools/javac/6917288/T6917288.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/6917288/T6917288.java	Tue Feb 13 00:03:02 2018 -0500
@@ -69,7 +69,14 @@
             return;
         }
 
-        check(classesDir, "Test.class", "Test$Inner.class", "Test$1.class");
+        switch (k) {
+            case ALWAYS:
+            case TRUE:
+                check(classesDir, "Test.class", "Test$Inner.class", "Test$1.class");
+                break;
+            default:
+                check(classesDir, "Test.class", "Test$Inner.class");
+        }
     }
 
     /**
--- a/test/langtools/tools/javac/7199823/InnerClassCannotBeVerified.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/7199823/InnerClassCannotBeVerified.java	Tue Feb 13 00:03:02 2018 -0500
@@ -29,6 +29,7 @@
  * @run main InnerClassCannotBeVerified
  */
 
+import java.nio.file.NoSuchFileException;
 import java.util.Arrays;
 import javax.tools.JavaFileObject;
 import java.net.URI;
@@ -43,6 +44,17 @@
 
 public class InnerClassCannotBeVerified {
 
+    enum CompilationKind {
+        PRE_NESTMATES("-source", "10", "-target", "10"),
+        POST_NESTMATES();
+
+        String[] opts;
+
+        CompilationKind(String... opts) {
+            this.opts = opts;
+        }
+    }
+
     private static final String errorMessage =
             "Compile error while compiling the following source:\n";
 
@@ -51,34 +63,49 @@
     }
 
     void run() throws Exception {
-        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
-        JavaSource source = new JavaSource();
-        JavacTask ct = (JavacTask)comp.getTask(null, null, null,
-                null, null, Arrays.asList(source));
-        try {
-            if (!ct.call()) {
+        for (CompilationKind ck : CompilationKind.values()) {
+            File file = new File("Test$1.class");
+            if (file.exists()) {
+                file.delete();
+            }
+            JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
+            JavaSource source = new JavaSource();
+            JavacTask ct = (JavacTask)comp.getTask(null, null, null,
+                    Arrays.asList(ck.opts), null, Arrays.asList(source));
+            try {
+                if (!ct.call()) {
+                    throw new AssertionError(errorMessage +
+                            source.getCharContent(true));
+                }
+            } catch (Throwable ex) {
                 throw new AssertionError(errorMessage +
                         source.getCharContent(true));
             }
-        } catch (Throwable ex) {
-            throw new AssertionError(errorMessage +
-                    source.getCharContent(true));
+            check(ck);
         }
-        check();
     }
 
-    private void check() throws IOException, ConstantPoolException {
-        File file = new File("Test$1.class");
-        ClassFile classFile = ClassFile.read(file);
-        boolean inheritsFromObject =
-                classFile.getSuperclassName().equals("java/lang/Object");
-        boolean implementsNoInterface = classFile.interfaces.length == 0;
-        boolean noMethods = classFile.methods.length == 0;
-        if (!(inheritsFromObject &&
-              implementsNoInterface &&
-              noMethods)) {
-            throw new AssertionError("The inner classes reused as " +
-                    "access constructor tag for this code must be empty");
+    private void check(CompilationKind ck) throws IOException, ConstantPoolException {
+        try {
+            File file = new File("Test$1.class");
+            ClassFile classFile = ClassFile.read(file);
+            if (ck == CompilationKind.POST_NESTMATES) {
+                throw new AssertionError("Unexpected constructor tag class!");
+            }
+            boolean inheritsFromObject =
+                    classFile.getSuperclassName().equals("java/lang/Object");
+            boolean implementsNoInterface = classFile.interfaces.length == 0;
+            boolean noMethods = classFile.methods.length == 0;
+            if (!(inheritsFromObject &&
+                    implementsNoInterface &&
+                    noMethods)) {
+                throw new AssertionError("The inner classes reused as " +
+                        "access constructor tag for this code must be empty");
+            }
+        } catch (NoSuchFileException ex) {
+            if (ck == CompilationKind.PRE_NESTMATES) {
+                throw new AssertionError("Constructor tag class missing!");
+            }
         }
     }
 
--- a/test/langtools/tools/javac/classfiles/attributes/SourceFile/SyntheticClassTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/classfiles/attributes/SourceFile/SyntheticClassTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -30,14 +30,30 @@
  *          jdk.compiler/com.sun.tools.javac.main
  *          jdk.jdeps/com.sun.tools.classfile
  * @build toolbox.ToolBox InMemoryFileManager TestBase SourceFileTestBase
- * @run main SyntheticClassTest
+ * @compile -source 10 -target 10 SyntheticClassTest.java
+ * @run main SyntheticClassTest true
+ * @clean SyntheticClassTest$1
+ * @compile SyntheticClassTest.java
+ * @run main SyntheticClassTest false
  */
 
+import java.nio.file.NoSuchFileException;
+
 public class SyntheticClassTest extends SourceFileTestBase {
     public static void main(String[] args) throws Exception {
+        boolean expectSynthetic = Boolean.parseBoolean(args[0]);
         new Inner();
 
-        new SyntheticClassTest().test("SyntheticClassTest$1", "SyntheticClassTest.java");
+        try {
+            new SyntheticClassTest().test("SyntheticClassTest$1", "SyntheticClassTest.java");
+            if (!expectSynthetic) {
+                throw new AssertionError("Synthetic class should not have been emitted!");
+            }
+        } catch (NoSuchFileException ex) {
+            if (expectSynthetic) {
+                throw new AssertionError("Synthetic class should have been emitted!");
+            }
+        }
     }
 
     static class Inner {
--- a/test/langtools/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateInnerClassMembersTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateInnerClassMembersTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -32,7 +32,7 @@
  * @library /tools/lib /tools/javac/lib ../lib
  * @build toolbox.ToolBox InMemoryFileManager TestResult
  * @build AccessToPrivateInnerClassMembersTest SyntheticTestDriver ExpectedClass ExpectedClasses
- * @run main SyntheticTestDriver AccessToPrivateInnerClassMembersTest 1
+ * @run main SyntheticTestDriver AccessToPrivateInnerClassMembersTest
  */
 
 /**
@@ -51,12 +51,10 @@
 @ExpectedClass(className = "AccessToPrivateInnerClassMembersTest$Inner1",
         expectedMethods = {"<init>(AccessToPrivateInnerClassMembersTest)", "function()"},
         expectedFields = "var",
-        expectedNumberOfSyntheticMethods = 4,
         expectedNumberOfSyntheticFields = 1)
 @ExpectedClass(className = "AccessToPrivateInnerClassMembersTest$Inner2",
         expectedMethods = {"function()", "staticFunction()", "<init>()"},
-        expectedFields = {"staticVar", "var"},
-        expectedNumberOfSyntheticMethods = 7)
+        expectedFields = {"staticVar", "var"})
 public class AccessToPrivateInnerClassMembersTest {
 
     private class Inner1 {
--- a/test/langtools/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateSiblingsTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/classfiles/attributes/Synthetic/AccessToPrivateSiblingsTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -32,7 +32,7 @@
  * @library /tools/lib /tools/javac/lib ../lib
  * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
  * @build AccessToPrivateSiblingsTest SyntheticTestDriver ExpectedClass ExpectedClasses
- * @run main SyntheticTestDriver AccessToPrivateSiblingsTest 1
+ * @run main SyntheticTestDriver AccessToPrivateSiblingsTest
  */
 
 /**
@@ -50,19 +50,16 @@
 @ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner1",
         expectedMethods = {"function()", "<init>(AccessToPrivateSiblingsTest)"},
         expectedFields = "var",
-        expectedNumberOfSyntheticMethods = 4,
         expectedNumberOfSyntheticFields = 1)
 @ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner2",
         expectedMethods = "<init>(AccessToPrivateSiblingsTest)",
         expectedNumberOfSyntheticFields = 1)
 @ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner3",
         expectedMethods = {"<init>()", "function()", "staticFunction()", "<clinit>()"},
-        expectedFields = {"var", "staticVar"},
-        expectedNumberOfSyntheticMethods = 4)
+        expectedFields = {"var", "staticVar"})
 @ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner4",
         expectedMethods = {"<init>()", "function()", "staticFunction()"},
-        expectedFields = {"var", "staticVar"},
-        expectedNumberOfSyntheticMethods = 4)
+        expectedFields = {"var", "staticVar"})
 public class AccessToPrivateSiblingsTest {
 
     private class Inner1 {
--- a/test/langtools/tools/javac/classfiles/attributes/Synthetic/BridgeMethodsForLambdaTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/classfiles/attributes/Synthetic/BridgeMethodsForLambdaTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -32,7 +32,7 @@
  * @library /tools/lib /tools/javac/lib ../lib
  * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
  * @build BridgeMethodsForLambdaTest SyntheticTestDriver ExpectedClass ExpectedClasses
- * @run main SyntheticTestDriver BridgeMethodsForLambdaTest 1
+ * @run main SyntheticTestDriver BridgeMethodsForLambdaTest
  */
 
 import java.util.Comparator;
@@ -58,15 +58,14 @@
 @ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner1",
         expectedMethods = {"<init>(BridgeMethodsForLambdaTest)", "function()", "run()"},
         expectedFields = "lambda1",
-        expectedNumberOfSyntheticMethods = 4,
+        expectedNumberOfSyntheticMethods = 1,
         expectedNumberOfSyntheticFields = 1)
 @ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner2",
         expectedMethods = {"<init>()", "staticFunction()"},
         expectedFields = "lambda1",
-        expectedNumberOfSyntheticMethods = 3)
+        expectedNumberOfSyntheticMethods = 1)
 @ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner3",
         expectedMethods = {"<init>(BridgeMethodsForLambdaTest)", "function()"},
-        expectedNumberOfSyntheticMethods = 1,
         expectedNumberOfSyntheticFields = 1)
 @ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner4",
         expectedMethods = {"<init>(BridgeMethodsForLambdaTest)", "function()"},
--- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesInInnerClassTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesInInnerClassTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -31,21 +31,30 @@
  *          jdk.jdeps/com.sun.tools.classfile
  * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
  * @build InnerClassesInInnerClassTestBase InnerClassesTestBase
- * @run main InnerClassesInInnerClassTest
+ * @run main InnerClassesInInnerClassTest true
+ * @run main InnerClassesInInnerClassTest false
  */
 
+import java.util.Arrays;
 import java.util.List;
 
 public class InnerClassesInInnerClassTest extends InnerClassesInInnerClassTestBase {
 
+    final boolean expectSyntheticClass;
+
+    public InnerClassesInInnerClassTest(boolean expectSyntheticClass) {
+        this.expectSyntheticClass = expectSyntheticClass;
+    }
+
     public static void main(String[] args) throws TestFailedException {
-        InnerClassesTestBase test = new InnerClassesInInnerClassTest();
+        boolean expectSyntheticClass = Boolean.parseBoolean(args[0]);
+        InnerClassesTestBase test = new InnerClassesInInnerClassTest(expectSyntheticClass);
         test.test("InnerClassesSrc$Inner", "Inner", "1");
     }
 
     @Override
     public void setProperties() {
-        setHasSyntheticClass(true);
+        setHasSyntheticClass(expectSyntheticClass);
         setOuterClassType(ClassType.CLASS);
         setInnerClassType(ClassType.CLASS);
     }
@@ -62,4 +71,11 @@
 
         return sources;
     }
+
+    @Override
+    protected List<String> getCompileOptions() {
+        return !expectSyntheticClass ?
+                super.getCompileOptions() :
+                Arrays.asList("-source", "10", "-target", "10");
+    }
 }
--- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesInInnerEnumTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesInInnerEnumTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -31,13 +31,24 @@
  *          jdk.jdeps/com.sun.tools.classfile
  * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
  * @build InnerClassesInInnerClassTestBase InnerClassesTestBase
- * @run main InnerClassesInInnerEnumTest
+ * @run main InnerClassesInInnerEnumTest true
+ * @run main InnerClassesInInnerEnumTest false
  */
 
+import java.util.Arrays;
+import java.util.List;
+
 public class InnerClassesInInnerEnumTest extends InnerClassesInInnerClassTestBase {
 
+    final boolean expectSyntheticClass;
+
+    public InnerClassesInInnerEnumTest(boolean expectSyntheticClass) {
+        this.expectSyntheticClass = expectSyntheticClass;
+    }
+
     public static void main(String[] args) throws TestFailedException {
-        InnerClassesTestBase test = new InnerClassesInInnerEnumTest();
+        boolean expectSyntheticClass = Boolean.parseBoolean(args[0]);
+        InnerClassesTestBase test = new InnerClassesInInnerEnumTest(expectSyntheticClass);
         test.test("InnerClassesSrc$Inner", "Inner", "1");
     }
 
@@ -46,8 +57,15 @@
         setOuterOtherModifiers(Modifier.EMPTY, Modifier.STATIC);
         setOuterClassType(ClassType.ENUM);
         setInnerClassType(ClassType.CLASS);
-        setHasSyntheticClass(true);
+        setHasSyntheticClass(expectSyntheticClass);
         setPrefix("Inner {;");
         setSuffix("}");
     }
+
+    @Override
+    protected List<String> getCompileOptions() {
+        return !expectSyntheticClass ?
+                super.getCompileOptions() :
+                Arrays.asList("-source", "10", "-target", "10");
+    }
 }
--- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -31,20 +31,29 @@
  *          jdk.jdeps/com.sun.tools.classfile
  * @build toolbox.ToolBox InMemoryFileManager TestResult TestBase
  * @build InnerClassesTestBase
- * @run main InnerClassesTest
+ * @run main InnerClassesTest true
+ * @run main InnerClassesTest false
  */
 
+import java.util.Arrays;
 import java.util.List;
 
 public class InnerClassesTest extends InnerClassesTestBase {
 
+    final boolean expectSyntheticClass;
+
+    public InnerClassesTest(boolean expectSyntheticClass) {
+        this.expectSyntheticClass = expectSyntheticClass;
+    }
+
     public static void main(String[] args) throws TestFailedException {
-        new InnerClassesTest().test("InnerClassesSrc");
+        boolean expectSyntheticClass = Boolean.parseBoolean(args[0]);
+        new InnerClassesTest(expectSyntheticClass).test("InnerClassesSrc");
     }
 
     private List<TestCase> generateClasses() {
         setInnerClassType(ClassType.CLASS);
-        setHasSyntheticClass(true);
+        setHasSyntheticClass(expectSyntheticClass);
         return super.generateTestCases();
     }
 
@@ -82,4 +91,11 @@
         sources.addAll(generateAnnotations());
         return sources;
     }
+
+    @Override
+    protected List<String> getCompileOptions() {
+        return !expectSyntheticClass ?
+                super.getCompileOptions() :
+                Arrays.asList("-source", "10", "-target", "10");
+    }
 }
--- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java	Tue Feb 13 00:03:02 2018 -0500
@@ -199,7 +199,7 @@
         printf("Testing :\n%s\n", test.getSource());
         try {
             Map<String, Set<String>> class2Flags = test.getFlags();
-            ClassFile cf = readClassFile(compile(test.getSource())
+            ClassFile cf = readClassFile(compile(getCompileOptions(), test.getSource())
                     .getClasses().get(classToTest));
             InnerClasses_attribute innerClasses = (InnerClasses_attribute)
                     cf.getAttribute(Attribute.InnerClasses);
@@ -324,6 +324,10 @@
         return flags;
     }
 
+    protected List<String> getCompileOptions() {
+        return Collections.emptyList();
+    }
+
     private List<List<Modifier>> getAllCombinations(Modifier[] accessModifiers, Modifier[] otherModifiers) {
         List<List<Modifier>> list = new ArrayList<>();
         for (Modifier access : accessModifiers) {
--- a/test/langtools/tools/javac/nativeHeaders/NativeHeaderTest.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/nativeHeaders/NativeHeaderTest.java	Tue Feb 13 00:03:02 2018 -0500
@@ -122,7 +122,7 @@
 
         // double check the synthetic class was generated
         checkEqual("generatedClasses",
-                createSet("C.class", "C$1.class", "C$Inner.class"),
+                createSet("C.class", "C$Inner.class"),
                 createSet(classesDir.list()));
     }
 
--- a/test/langtools/tools/javac/processing/model/completionfailure/NoAbortForBadClassFile.java	Sun Feb 11 20:26:22 2018 -0500
+++ b/test/langtools/tools/javac/processing/model/completionfailure/NoAbortForBadClassFile.java	Tue Feb 13 00:03:02 2018 -0500
@@ -120,6 +120,7 @@
 
         new toolbox.JavacTask(tb)
                 .outdir(out)
+                .options("-source", "10", "-target", "10")
                 .files(tb.findJavaFiles(src))
                 .run(Expect.SUCCESS)
                 .writeAll()