Search in sources :

Example 51 with Lookup

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

the class Find_InvokeTracker method test_GetterSetter_Private_CrossPackage_SuperclassLookup.

/**
 * Negative test : findSetter, findGetter tests using a superclass as lookup class and private fields
 * belonging to a sub-class under a different package than the lookup ( super ) class.
 * @throws Throwable
 */
@Test(groups = { "level.extended" })
public void test_GetterSetter_Private_CrossPackage_SuperclassLookup() throws Throwable {
    boolean illegalAccessExceptionThrown = false;
    Lookup superclassLookup = PackageExamples.getLookup();
    try {
        superclassLookup.findSetter(CrossPackageExampleSubclass.class, "nonStaticPrivateField_Child", int.class);
    } catch (IllegalAccessException e) {
        illegalAccessExceptionThrown = true;
    }
    AssertJUnit.assertTrue(illegalAccessExceptionThrown);
    illegalAccessExceptionThrown = false;
    try {
        superclassLookup.findGetter(CrossPackageExampleSubclass.class, "nonStaticPrivateField_Child", int.class);
    } catch (IllegalAccessException e) {
        illegalAccessExceptionThrown = true;
    }
    AssertJUnit.assertTrue(illegalAccessExceptionThrown);
}
Also used : Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 52 with Lookup

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

the class LookupInTests method testLookup_PublicNestedInnerClassLookup_Level1.

/**
 *************************************************
 * Tests involving nested public inner classes
 * ***********************************************
 */
/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is a second level inner class under the old lookup class which is a first level inner class.
 * Basically we validate that a nested class C.D can access private members within another nested class C.D.E.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_PublicNestedInnerClassLookup_Level1() throws Throwable {
    Lookup inObj = samePackageInnerClassLookup.in(SamePackageInnerClass_Nested_Level2.class);
    assertClassAndMode(inObj, SamePackageInnerClass_Nested_Level2.class, FULL_ACCESS_MODE);
}
Also used : MethodHandles.publicLookup(java.lang.invoke.MethodHandles.publicLookup) Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 53 with Lookup

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

the class LookupInTests method testLookup_PublicInnerClassLookup.

/**
 *************************************************
 * Tests involving public inner classes
 * ***********************************************
 */
/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is a public inner class under the old lookup class.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_PublicInnerClassLookup() throws Throwable {
    Lookup inObj = samePackageExampleLookup.in(SamePackageInnerClass.class);
    assertClassAndMode(inObj, SamePackageInnerClass.class, FULL_ACCESS_MODE);
}
Also used : MethodHandles.publicLookup(java.lang.invoke.MethodHandles.publicLookup) Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 54 with Lookup

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

the class LookupInTests method testLookup_CrossPackageLookup_Superclass.

/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is the superclass of the old lookup class but is residing in a
 * different package than the old lookup class.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_CrossPackageLookup_Superclass() throws Throwable {
    Lookup lookup = CrossPackageExampleSubclass.getLookup();
    Lookup inObject = lookup.in(PackageExamples.class);
    assertClassAndMode(inObject, PackageExamples.class, MODULE_PUBLIC_MODE);
}
Also used : MethodHandles.publicLookup(java.lang.invoke.MethodHandles.publicLookup) Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 55 with Lookup

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

the class LookupInTests method testLookup_StaticInnerClassLookup.

/**
 *************************************************
 * Tests involving static inner classes
 * ***********************************************
 */
/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is a static inner class under the old lookup class.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_StaticInnerClassLookup() throws Throwable {
    Lookup inObj = samePackageExampleLookup.in(SamePackageInnerClass_Static.class);
    assertClassAndMode(inObj, SamePackageInnerClass_Static.class, FULL_ACCESS_MODE);
}
Also used : MethodHandles.publicLookup(java.lang.invoke.MethodHandles.publicLookup) Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Aggregations

Lookup (java.lang.invoke.MethodHandles.Lookup)216 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)36 SamePackageInnerClass (com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass)17 MutableCallSite (java.lang.invoke.MutableCallSite)11 MethodHandles (java.lang.invoke.MethodHandles)9 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