use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class Find_InvokeTracker method test_GetterSetter_Public_SamePackage_InnerClasses_Parallel_Level2.
/**
* findSetter, findGetter test using fields of a second level inner class
* where the lookup class is another second level inner class of the same outer class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Public_SamePackage_InnerClasses_Parallel_Level2() throws Throwable {
SamePackageExample spe = new SamePackageExample();
SamePackageInnerClass spe_inner1 = spe.new SamePackageInnerClass();
SamePackageInnerClass_Nested_Level2 spe_inner2 = spe_inner1.new SamePackageInnerClass_Nested_Level2();
Lookup publicLookup = spe_inner2.getLookup();
MethodHandle mhSetter = publicLookup.findSetter(SamePackageExample.SamePackageInnerClass2.SamePackageInnerClass2_Nested_Level2.class, "nonStaticPublicField_Inner22", int.class);
MethodHandle mhGetter = publicLookup.findGetter(SamePackageExample.SamePackageInnerClass2.SamePackageInnerClass2_Nested_Level2.class, "nonStaticPublicField_Inner22", int.class);
SamePackageExample.SamePackageInnerClass2.SamePackageInnerClass2_Nested_Level2 g = ((new SamePackageExample()).new SamePackageInnerClass2()).new SamePackageInnerClass2_Nested_Level2();
mhSetter.invokeExact(g, 5);
int o = (int) mhGetter.invokeExact(g);
AssertJUnit.assertEquals(o, 5);
}
use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class Find_InvokeTracker method test_GetterSetter_Private_SamePackage_SubclassLookup.
/**
* Negative test : findSetter, findGetter tests using a sub-class Lookup and super-class private fields where both super and sub
* classes belong to the same package.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Private_SamePackage_SubclassLookup() throws Throwable {
Lookup subclassLookup = SamePackageExampleSubclass.getLookup();
boolean illegalAccessExceptionThrown = false;
try {
subclassLookup.findSetter(SamePackageExample.class, "nonStaticPrivateField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
/*findSetter access to private field of parent should be given to child*/
AssertJUnit.assertFalse(illegalAccessExceptionThrown);
illegalAccessExceptionThrown = false;
try {
subclassLookup.findGetter(SamePackageExample.class, "nonStaticPrivateField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
/*findSetter access to private field of parent should be given to child*/
AssertJUnit.assertFalse(illegalAccessExceptionThrown);
}
use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class Find_InvokeTracker method test_GetterSetter_Private_Static_SamePackage.
/*private static fields ( same package )*/
/**
* Negative test : findGetter, findSetter test using a Lookup whose lookup class is LookupAPITests_find(this class)
* and lookup fields are private static fields belonging to a different class under the same package as the lookup class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Private_Static_SamePackage() throws Throwable {
Lookup publicLookup = MethodHandles.lookup();
boolean illegalAccessExceptionThrown = false;
try {
publicLookup.findSetter(SamePackageExample.class, "staticPrivateField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
illegalAccessExceptionThrown = false;
try {
publicLookup.findGetter(SamePackageExample.class, "staticPrivateField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
// make sure we get access exception when trying to access static field with findGetter/findSetter
if (illegalAccessExceptionThrown = false) {
Assert.fail("Illegal access to static private field given to findSetter/findGetter");
}
illegalAccessExceptionThrown = false;
try {
publicLookup.findStaticSetter(SamePackageExample.class, "staticPrivateField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
illegalAccessExceptionThrown = false;
try {
publicLookup.findStaticGetter(SamePackageExample.class, "staticPrivateField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
}
use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class Find_InvokeTracker method test_GetterSetter_Public_CrossPackage_SuperclassLookup.
/**
* findSetter, findGetter tests using a super-class as lookup class and public 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_Public_CrossPackage_SuperclassLookup() throws Throwable {
Lookup superclassLookup = PackageExamples.getLookup();
MethodHandle mhSetter = superclassLookup.findSetter(CrossPackageExampleSubclass.class, "nonStaticPublicField_Child", int.class);
MethodHandle mhGetter = superclassLookup.findGetter(CrossPackageExampleSubclass.class, "nonStaticPublicField_Child", int.class);
CrossPackageExampleSubclass g = new CrossPackageExampleSubclass();
mhSetter.invokeExact(g, 5);
int o = (int) mhGetter.invoke(g);
AssertJUnit.assertEquals(o, 5);
}
use of java.lang.invoke.MethodHandles.lookup in project openj9 by eclipse.
the class Find_InvokeTracker method test_GetterSetter_Private_Static_SamePackage_SuperClassLookup.
/**
* Negative test : findGetter, findSetter test using a Lookup whose lookup class is a super-class and
* and lookup fields are private static fields belonging to a subclass of the lookup class under the same
* package as the lookup class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Private_Static_SamePackage_SuperClassLookup() throws Throwable {
Lookup superclassLookup = SamePackageExample.getLookup();
boolean illegalAccessExceptionThrown = false;
try {
superclassLookup.findSetter(SamePackageExampleSubclass.class, "staticPrivateField_Child", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
illegalAccessExceptionThrown = false;
try {
superclassLookup.findGetter(SamePackageExampleSubclass.class, "staticPrivateField_Child", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
// make sure we get access exception when trying to access static field with findGetter/findSetter
if (illegalAccessExceptionThrown = false) {
Assert.fail("Illegal access to static private field given to findSetter/findGetter");
}
illegalAccessExceptionThrown = false;
try {
superclassLookup.findStaticSetter(SamePackageExampleSubclass.class, "staticPrivateField_Child", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
illegalAccessExceptionThrown = false;
try {
superclassLookup.findStaticGetter(SamePackageExampleSubclass.class, "staticPrivateField_Child", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
}
Aggregations