1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8189335
  27  * @summary Synthetic anonymous class used as access constructor tag conflicting with a top level class.
  28  * @modules jdk.compiler/com.sun.tools.javac.api
  29  *          jdk.compiler/com.sun.tools.javac.main
  30  *          jdk.jdeps/com.sun.tools.classfile
  31  * @library /tools/lib /tools/javac/lib ../lib
  32  * @build toolbox.ToolBox InMemoryFileManager TestResult
  33  * @build AccessToPrivateInnerClassConstructorsTest SyntheticTestDriver ExpectedClass ExpectedClasses
  34  * @run main SyntheticTestDriver AccessToPrivateInnerClassConstructorsTest 0
  35  * @run main AccessToPrivateInnerClassConstructorsTest
  36  */
  37 
  38 @ExpectedClass(className = "AccessToPrivateInnerClassConstructorsTest",
  39         expectedMethods = {"<init>()", "main(java.lang.String[])", "f()", "g()"})
  40 @ExpectedClass(className = "AccessToPrivateInnerClassConstructorsTest$1",
  41         expectedMethods = {"<init>()"})
  42 @ExpectedClass(className = "AccessToPrivateInnerClassConstructorsTest$A",
  43         expectedMethods = {
  44                 "<init>(AccessToPrivateInnerClassConstructorsTest)",
  45                 "<init>(AccessToPrivateInnerClassConstructorsTest, " +
  46                        "AccessToPrivateInnerClassConstructorsTest$1)"},
  47         expectedNumberOfSyntheticFields = 1,
  48         expectedNumberOfSyntheticMethods = 0)
  49 @ExpectedClass(className = "AccessToPrivateInnerClassConstructorsTest$1Local",
  50         expectedMethods = {"<init>(AccessToPrivateInnerClassConstructorsTest)"},
  51         expectedNumberOfSyntheticFields = 1)
  52 @ExpectedClass(className = "AccessToPrivateInnerClassConstructorsTest$2Local",
  53         expectedMethods = {"<init>(AccessToPrivateInnerClassConstructorsTest)"},
  54         expectedNumberOfSyntheticFields = 1)
  55 public class AccessToPrivateInnerClassConstructorsTest {
  56 
  57     public static void main(String... args) {
  58         new AccessToPrivateInnerClassConstructorsTest().f();
  59     }
  60 
  61     private class A {
  62         private A() { }
  63         private A(AccessToPrivateInnerClassConstructorsTest$1 o) { }
  64     }
  65 
  66     void f() {
  67         new A();
  68         new A(null);
  69 
  70         class Local {};
  71         new Local();
  72     }
  73 
  74     void g() {
  75         class Local {};
  76         new Local();
  77     }
  78 }
  79 class AccessToPrivateInnerClassConstructorsTest$1 {}