< prev index next >

test/hotspot/jtreg/runtime/Nestmates/privateConstructors/TestReflection.java

Print this page




  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 8046171
  27  * @summary Test access to private constructors between nestmates and nest-top
  28  *          using different flavours of named nested types using core reflection
  29  * @run main TestReflection

  30  */
  31 






  32 public class TestReflection {
  33 
  34     // All constructors are private to ensure nestmate access checks apply
  35 
  36     // All doConstruct methods are public so they don't involve invoke_special
  37 
  38     private TestReflection() {}
  39 
  40     // The various nestmates
  41 
  42     // Note: No constructor on interfaces so no StaticIface variants
  43 
  44     static interface StaticIface {
  45 
  46         // Methods that will access private constructors of nestmates.
  47         // The arg is a dummy for overloading purposes
  48 
  49         default void doConstruct(TestReflection o) throws Throwable {
  50           Object obj = o.getClass().getDeclaredConstructor(new Class<?>[0]).newInstance(new Object[0]);
  51         }
  52         default void doConstruct(TestReflection tr, InnerNested o) throws Throwable {
  53           Object obj = InnerNested.class.getDeclaredConstructor(new Class<?>[] {TestReflection.class}).newInstance(new Object[] { tr });
  54         }
  55         default void doConstruct(StaticNested o) throws Throwable {
  56           Object obj = o.getClass().getDeclaredConstructor(new Class<?>[0]).newInstance(new Object[0]);
  57         }
  58     }
  59 
  60     static class StaticNested {
  61 
  62         private StaticNested() {}
  63 
  64         // Methods that will access private constructors of nestmates.
  65         // The arg is a dummy for overloading purposes
  66 
  67         public void doConstruct(TestReflection o) throws Throwable {




  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 8046171
  27  * @summary Test access to private constructors between nestmates and nest-top
  28  *          using different flavours of named nested types using core reflection
  29  * @run main TestReflection
  30  * @run main/othervm -Dsun.reflect.noInflation=true TestReflection
  31  */
  32 
  33 // The first run will use NativeConstructorAccessor and due to the limited
  34 // number of calls we will not reach the inflation threshold.
  35 // The second run disables inflation so we will use the
  36 // GeneratedConstructorAccessor instead.
  37 // In this way both sets of Reflection classes are tested.
  38 
  39 public class TestReflection {
  40 
  41     // All constructors are private to ensure nestmate access checks apply
  42 
  43     // All doConstruct methods are public so they don't involve invoke_special
  44 
  45     private TestReflection() {}
  46 
  47     // The various nestmates
  48 
  49     // Note: No constructor on interfaces so no StaticIface variants
  50 
  51     static interface StaticIface {
  52 
  53         // Methods that will access private constructors of nestmates.

  54 
  55         default void doConstruct(TestReflection o) throws Throwable {
  56           Object obj = o.getClass().getDeclaredConstructor(new Class<?>[0]).newInstance(new Object[0]);
  57         }
  58         default void doConstruct(TestReflection tr, InnerNested o) throws Throwable {
  59           Object obj = InnerNested.class.getDeclaredConstructor(new Class<?>[] {TestReflection.class}).newInstance(new Object[] { tr });
  60         }
  61         default void doConstruct(StaticNested o) throws Throwable {
  62           Object obj = o.getClass().getDeclaredConstructor(new Class<?>[0]).newInstance(new Object[0]);
  63         }
  64     }
  65 
  66     static class StaticNested {
  67 
  68         private StaticNested() {}
  69 
  70         // Methods that will access private constructors of nestmates.
  71         // The arg is a dummy for overloading purposes
  72 
  73         public void doConstruct(TestReflection o) throws Throwable {


< prev index next >