Search in sources :

Example 56 with MethodHandles.lookup

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

the class LookupInTests method testLookup_PublicInnerClassLookup_ParallelInnerClasses_Level2.

/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is an second level inner class that shares the same top level outer class as the old lookup class which is
 * another second level inner class. Basically we validate that a nested class C.D.E can access private members within another
 * nested class C.B.F
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_PublicInnerClassLookup_ParallelInnerClasses_Level2() throws Throwable {
    SamePackageExample spe = new SamePackageExample();
    SamePackageInnerClass spei_level1 = spe.new SamePackageInnerClass();
    SamePackageInnerClass_Nested_Level2 spei_level2 = spei_level1.new SamePackageInnerClass_Nested_Level2();
    Lookup lookup = spei_level2.getLookup();
    Lookup inObj = lookup.in(SamePackageInnerClass2_Nested_Level2.class);
    assertClassAndMode(inObj, SamePackageInnerClass2_Nested_Level2.class, FULL_ACCESS_MODE);
}
Also used : MethodHandles.publicLookup(java.lang.invoke.MethodHandles.publicLookup) Lookup(java.lang.invoke.MethodHandles.Lookup) SamePackageInnerClass_Nested_Level2(com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2) SamePackageInnerClass(com.ibm.j9.jsr292.SamePackageExample.SamePackageInnerClass) Test(org.testng.annotations.Test)

Example 57 with MethodHandles.lookup

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

the class LookupInTests method test_Lookup_toString.

/**
 *Test for MethodHandles.Lookup.toString() class where we check output depending on various access modes.
 */
@Test(groups = { "level.sanity" })
public void test_Lookup_toString() {
    Assert.assertEquals("java.lang.Object/publicLookup", localPublicLookup.toString());
    Lookup inObject = packageExamplesLookup.in(Object.class);
    Assert.assertEquals("java.lang.Object/public", inObject.toString());
    Lookup inAssertObject = localLookup.in(Assert.class);
    Assert.assertEquals("org.testng.Assert/module", inAssertObject.toString());
    Lookup inCrossPackageClass = samePackageExampleLookup.in(PackageExamples.class);
    Assert.assertEquals("examples.PackageExamples/module", inCrossPackageClass.toString());
    Lookup inSamePackageClass = samePackageExampleLookup.in(SamePackageSingleMethodInterfaceExample.class);
    Assert.assertEquals("com.ibm.j9.jsr292.SamePackageSingleMethodInterfaceExample/package", inSamePackageClass.toString());
    Lookup inAccessClass = localLookup.in(PackageClass.class);
    Assert.assertEquals("com.ibm.j9.jsr292.LookupInTests$PackageClass", inAccessClass.toString());
    Lookup inNoAccess = localPublicLookup.in(PackageClass.class);
    Assert.assertEquals("com.ibm.j9.jsr292.LookupInTests$PackageClass/noaccess", inNoAccess.toString());
}
Also used : MethodHandles.publicLookup(java.lang.invoke.MethodHandles.publicLookup) Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 58 with MethodHandles.lookup

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

the class LookupInTests method testLookup_StaticdOuterClassLookup.

/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is the outer class of the original lookup class.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_StaticdOuterClassLookup() throws Throwable {
    Lookup lookup = SamePackageExample.SamePackageInnerClass_Static.getLookup();
    Lookup inObj = lookup.in(SamePackageExample.class);
    assertClassAndMode(inObj, SamePackageExample.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 59 with MethodHandles.lookup

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

the class LookupInTests method testLookup_inObject_Using_publicLookup.

/**
 * Using an old lookup object that was created from a call to MethodHandles.publicLookup(),
 * validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is java.lang.Object.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_inObject_Using_publicLookup() throws Throwable {
    Lookup lookup = PackageExamples.getPublicLookup();
    Lookup inObject = lookup.in(int.class);
    /*NOTE:
		 * This is equivalent of the failing test case above, but this one works.
		 * The only difference is here we are using MethodHandles.publicLookup() 
		 * instead of MethodHandles.lookup() to obtain the original Lookup object.
		 * */
    assertClassAndMode(inObject, int.class, MethodHandles.Lookup.PUBLIC);
}
Also used : MethodHandles.publicLookup(java.lang.invoke.MethodHandles.publicLookup) Lookup(java.lang.invoke.MethodHandles.Lookup) Test(org.testng.annotations.Test)

Example 60 with MethodHandles.lookup

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

the class LookupInTests method testLookup_PublicInnerClassLookup_CrossPackage.

/**
 * 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 inside a top level class belonging to a different
 * package than the old lookup class.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_PublicInnerClassLookup_CrossPackage() throws Throwable {
    Lookup inObj = packageExamplesLookup.in(SamePackageInnerClass.class);
    assertClassAndMode(inObj, SamePackageInnerClass.class, MODULE_PUBLIC_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