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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations