Search in sources :

Example 11 with MethodHandles.lookup

use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.

the class Test_ReflectionAndMethodHandles method test_find_special_child_public_static.

/**
 * This method is a negative test to verify that the methodHandle for the public 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_public_static() throws Exception {
    Class<?> c = Class.forName("ITestChild", true, loadClass);
    Lookup lookup = getLookupObject(c);
    try {
        MethodHandle mh = lookup.findSpecial(c, "child_public_static_method", type, Test_ReflectionAndMethodHandles.class);
        Assert.fail("Should have thrown an IllegalAccessException");
    } catch (IllegalAccessException e) {
    /* Pass */
    }
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 12 with MethodHandles.lookup

use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.

the class Test_ReflectionAndMethodHandles method test_find_special_ancestor_private_static.

/**
 * This method is a negative test to verify that the methodHandle for the private static
 * method from the parent interface cannot be successfully looked up using findSpecial.
 * An IllegalAccessException is expected to be thrown
 * @throws IllegalAccessException
 */
@Test
public static void test_find_special_ancestor_private_static() throws Exception {
    Class<?> c = Class.forName("ITestChild", true, loadClass);
    Lookup lookup = getLookupObject(c);
    try {
        MethodHandle mh = lookup.findSpecial(c, "private_static_method", type, Test_ReflectionAndMethodHandles.class);
        Assert.fail("Should have thrown an IllegalAccessException");
    } catch (Exception e) {
        AssertJUnit.assertTrue("Failing test as expected IllegalAccessException to get thrown, instead of " + e, e instanceof IllegalAccessException);
    }
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 13 with MethodHandles.lookup

use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.

the class Test_ReflectionAndMethodHandles method test_find_special_ancestor_private_non_static.

/**
 * This method is a negative test to verify that the methodHandle for the private non static
 * method from the parent interface cannot be successfully looked up using findSpecial.
 * An IllegalAccessException is expected to be thrown
 * @throws IllegalAccessException
 */
@Test
public static void test_find_special_ancestor_private_non_static() throws Exception {
    Class<?> c = Class.forName("ITestChild", true, loadClass);
    Lookup lookup = getLookupObject(c);
    try {
        MethodHandle mh = lookup.findSpecial(c, "private_non_static_method", type, Test_ReflectionAndMethodHandles.class);
        Assert.fail("Should have thrown an IllegalAccessException");
    } catch (IllegalAccessException e) {
    /* Pass */
    }
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 14 with MethodHandles.lookup

use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.

the class Test_ReflectionAndMethodHandles method test_find_static_ancestor_private_static.

/**
 * This method is a negative test to verify that the methodHandle for the private static
 * method from the parent interface ITest cannot be successfully looked up using findStatic.
 * A NoSuchMethodException is expected to be thrown
 * @throws NoSuchMethodException
 */
@Test
public static void test_find_static_ancestor_private_static() throws Exception {
    Class<?> c = Class.forName("ITestChild", true, loadClass);
    Lookup lookup = getLookupObject(c);
    try {
        MethodHandle mh = lookup.findStatic(c, "private_static_method", type);
        Assert.fail("Should have thrown a NoSuchMethodException");
    } catch (NoSuchMethodException e) {
    /* Pass */
    }
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 15 with MethodHandles.lookup

use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.

the class Test_ReflectionAndMethodHandles method test_find_special_ancestor_public_static.

/**
 * This method is a negative test to verify that the methodHandle for the public static
 * method from the parent interface cannot be successfully looked up using findSpecial.
 * An IllegalAccessException is expected to be thrown
 * @throws IllegalAccessException
 */
@Test
public static void test_find_special_ancestor_public_static() throws Exception {
    Class<?> c = Class.forName("ITestChild", true, loadClass);
    Lookup lookup = getLookupObject(c);
    try {
        MethodHandle mh = lookup.findSpecial(c, "RunTest_private_static_method_with_InvokeStatic", type, Test_ReflectionAndMethodHandles.class);
        Assert.fail("Should have thrown an IllegalAccessException");
    } catch (IllegalAccessException e) {
    /* Pass */
    }
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Aggregations

Lookup (java.lang.invoke.MethodHandles.Lookup)218 Test (org.testng.annotations.Test)176 MethodHandle (java.lang.invoke.MethodHandle)96 MethodHandles.publicLookup (java.lang.invoke.MethodHandles.publicLookup)39 Method (java.lang.reflect.Method)37 SamePackageInnerClass (com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass)17 MutableCallSite (java.lang.invoke.MutableCallSite)11 MethodHandles (java.lang.invoke.MethodHandles)10 SamePackageInnerClass_Nested_Level2 (com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2)7 PackageExamples (examples.PackageExamples)7 MethodHandles.constant (java.lang.invoke.MethodHandles.constant)4 MethodHandles.dropArguments (java.lang.invoke.MethodHandles.dropArguments)4 MethodHandles.exactInvoker (java.lang.invoke.MethodHandles.exactInvoker)4 MethodHandles.foldArguments (java.lang.invoke.MethodHandles.foldArguments)4 MethodType.methodType (java.lang.invoke.MethodType.methodType)4 Constructor (java.lang.reflect.Constructor)4 ArrayList (java.util.ArrayList)4 Objects (java.util.Objects)4 Function (java.util.function.Function)4 ToDoubleFunction (java.util.function.ToDoubleFunction)4