--- old/test/runtime/valhalla/nestmates/MethodHandleInheritTest.java 2016-11-24 14:35:21.000000000 +0300 +++ new/test/runtime/valhalla/nestmates/MethodHandleInheritTest.java 2016-11-24 14:35:21.000000000 +0300 @@ -33,6 +33,7 @@ * @summary Verify parent's protected and private methods access from children classes using MethodHandles * @library / * @modules java.base + * @compile -XDdisableAccessors p2/MethodHandleSubTop.java * @run testng runtime.valhalla.nestmates.MethodHandleInheritTest */ public class MethodHandleInheritTest { @@ -53,51 +54,92 @@ innerInner = inner.new InnerInner(); } + /** + * negative case, to verify that there is no access to private method of the parent class from its child + */ @Test(expectedExceptions = {IllegalAccessException.class}) public void testPrivateMethodNeg() throws NoSuchMethodException, IllegalAccessException { methodHandleSubTop.getSuperMethodMH(METHOD_NAME_PRIVATE); } + /** + * negative case, to verify that there is no access to private field of the parent class from its child + */ @Test(expectedExceptions = {IllegalAccessException.class}) public void testPrivateFieldNeg() throws NoSuchFieldException, IllegalAccessException { methodHandleSubTop.getSuperFieldMH(FIELD_NAME_PRIVATE); } - @Test(expectedExceptions = {NoSuchMethodException.class}) - public void testProtectedMethodFromInnerNeg() throws NoSuchMethodException, IllegalAccessException { - inner.getSuperMethodMH(METHOD_NAME_PROTECTED); + /** + * positive case, to verify that there is access to protected method of the parent class from its child's inner class + */ + @Test + public void testProtectedMethodFromInnerPos() throws Throwable { + Assert.assertEquals((int) inner.getSuperMethodMH(METHOD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "inner -> top -> parent method"); } - @Test(expectedExceptions = {NoSuchFieldException.class}) - public void testProtectedFieldFromInnerNeg() throws NoSuchFieldException, IllegalAccessException { - inner.getSuperFieldMH(FIELD_NAME_PROTECTED); + /** + * positive case, to verify that there is access to protected field of the parent class from its child's inner class + */ + @Test + public void testProtectedFieldFromInnerPos() throws Throwable { + Assert.assertEquals((int) inner.getSuperFieldMH(FIELD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "inner -> top -> parent field"); } - @Test(expectedExceptions = {NoSuchMethodException.class}) - public void testProtectedMethodFromInnerInnerNeg() throws NoSuchMethodException, IllegalAccessException { - innerInner.getSuperMethodMH(METHOD_NAME_PROTECTED); + /** + * positive case, to verify that there is access to protected method of the parent class from its child's inner inner class + */ + @Test + public void testProtectedMethodFromInnerInnerPos() throws Throwable { + Assert.assertEquals((int) innerInner.getSuperMethodMH(METHOD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "innerInner -> inner -> top -> parent method"); } - @Test(expectedExceptions = {NoSuchFieldException.class}) - public void testProtectedFieldFromInnerInnerNeg() throws NoSuchFieldException, IllegalAccessException { - innerInner.getSuperFieldMH(FIELD_NAME_PROTECTED); + /** + * positive case, to verify that there is access to protected field of the parent class from its child's inner inner class + */ + @Test + public void testProtectedFieldFromInnerInnerPos() throws Throwable { + Assert.assertEquals((int) innerInner.getSuperFieldMH(FIELD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "innerInner -> inner -> top -> parent field"); } + /** + * positive case, to verify that there is access to protected field and method of the parent class from its child + */ @Test public void testProtectedAccessFromTopPos() throws Throwable { Assert.assertEquals((int) methodHandleSubTop.getSuperMethodMH(METHOD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "top -> parent method"); Assert.assertEquals((int) methodHandleSubTop.getSuperFieldMH(FIELD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "top -> parent field"); } - @Test - public void testProtectedAccessFromInnerPos() throws Throwable { - Assert.assertEquals((int) inner.getSuperProtectedMethodMH().invokeExact(methodHandleSubTop), 1, "inner -> top -> parent method"); - Assert.assertEquals((int) inner.getSuperProtectedFieldMH().invokeExact(methodHandleSubTop), 1, "inner -> top -> parent field"); + /** + * negative case, to verify that there is no method access bridge in top accessing from inner + */ + @Test(expectedExceptions = {NoSuchMethodException.class}) + public void testProtectedMethodAccessFromInnerNeg() throws Throwable { + inner.getSuperProtectedMethodMH(); } - @Test - public void testProtectedAccessFromInnerInnerPos() throws Throwable { - Assert.assertEquals((int) innerInner.getSuperProtectedMethodMH().invokeExact(methodHandleSubTop), 1, "innerInner -> inner -> top -> parent method"); - Assert.assertEquals((int) innerInner.getSuperProtectedFieldMH().invokeExact(methodHandleSubTop), 1, "innerInner -> inner -> top -> parent field"); + /** + * negative case, to verify that there is no field access bridge in top accessing from inner + */ + @Test(expectedExceptions = {NoSuchMethodException.class}) + public void testProtectedFieldAccessFromInnerNeg() throws Throwable { + inner.getSuperProtectedFieldMH(); + } + + /** + * negative case, to verify that there is no method access bridge in top accessing from inner's inner + */ + @Test(expectedExceptions = {NoSuchMethodException.class}) + public void testProtectedMethodAccessFromInnerInnerNeg() throws Throwable { + innerInner.getSuperProtectedMethodMH(); + } + + /** + * negative case, to verify that there is no field access bridge in top accessing from inner's inner + */ + @Test(expectedExceptions = {NoSuchMethodException.class}) + public void testProtectedFieldAccessFromInnerInnerNeg() throws Throwable { + innerInner.getSuperProtectedFieldMH(); } } --- old/test/runtime/valhalla/nestmates/p2/MethodHandleSubTop.java 2016-11-24 14:35:22.000000000 +0300 +++ new/test/runtime/valhalla/nestmates/p2/MethodHandleSubTop.java 2016-11-24 14:35:22.000000000 +0300 @@ -31,8 +31,8 @@ public class MethodHandleSubTop extends Sup { - private final MethodHandles.Lookup METHOD_HANDLE_LOOKUP = MethodHandles.lookup(); - private final MethodType METHOD_TYPE = MethodType.methodType(int.class); + final MethodHandles.Lookup METHOD_HANDLE_LOOKUP = MethodHandles.lookup(); + final MethodType METHOD_TYPE = MethodType.methodType(int.class); // verify access check to a "super" method, method can be used in positive and negative test case public MethodHandle getSuperMethodMH(String methodName) throws NoSuchMethodException, IllegalAccessException {