use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.
the class Test_ReflectionAndMethodHandles method test_find_virtual_ancestor_public_non_static.
/**
* This method is a test to verify that the methodHandle for the public non static
* method from the parent interface ITest can be successfully looked up using findVirtual, and then a
* negative test to verify that the method cannot be invoked. Here an IncompatibleClassChangeError is
* expected to be thrown
* @throws IncompatibleClassChangeError
*/
@Test
public static void test_find_virtual_ancestor_public_non_static() throws Throwable {
Class<?> c = Class.forName("ITestChild", true, loadClass);
Lookup lookup = getLookupObject(c);
MethodHandle mh = lookup.findVirtual(c, "RunTest_private_non_static_method_with_InvokeStatic", type);
try {
String returnStatement = (String) mh.invoke(instance);
Assert.fail("Failing as expected IncompatibleClassChangeError to be thrown when invoking method " + "RunTest_private_non_static_method_with_InvokeStatic");
} catch (IncompatibleClassChangeError e) {
/* Pass */
}
}
use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.
the class Test_ReflectionAndMethodHandles method test_unreflectSpecial_interface_ITest_private_static_method.
/**
* This method is a negative test to verify that the methodHandle for the private static method
* from the parent interface cannot be successfully produced using unreflectSpecial.
* An IllegalAccessException is expected to be thrown
* @throws IllegalAccessException
*/
@Test
public static void test_unreflectSpecial_interface_ITest_private_static_method() throws Throwable {
Class<?> d = Class.forName("ITest", true, loadClass);
Method method = d.getDeclaredMethod("private_static_method");
method.setAccessible(true);
Lookup lookup = getLookupObject(d);
try {
MethodHandle mh = lookup.unreflectSpecial(method, d);
Assert.fail("Should have thrown an IllegalAccessException");
} catch (IllegalAccessException e) {
/* Pass */
}
}
use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.
the class Test_ReflectionAndMethodHandles method test_find_static_child_public_static.
/**
* This method is used to verify if the method handle of a public static method
* in our child interface can be successfully looked up using findStatic, and then
* successfully invoke the method to verify that the correct MethodHandle was found
*/
@Test
public static void test_find_static_child_public_static() throws Throwable {
Class<?> c = Class.forName("ITestChild", true, loadClass);
Lookup lookup = getLookupObject(c);
MethodHandle mh = lookup.findStatic(c, "child_public_static_method", type);
String returnStatement = (String) mh.invoke();
AssertJUnit.assertEquals("Failing as public static method of child interface didnt return expected output when invoked", expected_child_public_static, returnStatement);
}
use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.
the class Test_ReflectionAndMethodHandles method test_find_special_child_private_static.
/* --------------- Tests to test findSpecial ---------------------- */
/**
* This method is a negative test to verify that the methodHandle for the private static
* method from the child interface cannot be successfully looked up using findSpecial.
* An IllegalAccessException is expected to be thrown
* @throws IllegalAccessException
*/
@Test
public static void test_find_special_child_private_static() throws Exception {
Class<?> c = Class.forName("ITestChild", true, loadClass);
Lookup lookup = getLookupObject(c);
try {
MethodHandle mh = lookup.findSpecial(c, "child_private_static_method", type, Test_ReflectionAndMethodHandles.class);
Assert.fail("Should have thrown an IllegalAccessException");
} catch (IllegalAccessException e) {
/* Pass */
}
}
use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.
the class Test_ReflectionAndMethodHandles method test_find_static_child_private_non_static.
/**
* This method is a negative test to verify that the methodHandle for the private non static
* method cannot be successfully looked up using findStatic. An IllegalAccessException is expected to be thrown
* @throws IllegalAccessException
*/
@Test
public static void test_find_static_child_private_non_static() throws Exception {
Class<?> c = Class.forName("ITestChild", true, loadClass);
Lookup lookup = getLookupObject(c);
try {
MethodHandle mh = lookup.findStatic(c, "child_private_non_static_method", type);
Assert.fail("Should have thrown an IllegalAccessException");
} catch (IllegalAccessException e) {
/* Pass */
}
}
Aggregations