use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.
the class Find_InvokeTracker method test_GetterSetter_Private_Static_CrossPackage_SuperclassLookup.
/**
* Negative test : findStaticGetter, findStaticSetter tests using private static fields of a sub-class belonging
* to a different package than the lookup class ( which is the super-class of the class containing the fields being looked up.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Private_Static_CrossPackage_SuperclassLookup() throws Throwable {
boolean illegalAccessExceptionThrown = false;
Lookup superclassLookup = PackageExamples.getLookup();
try {
superclassLookup.findStaticSetter(CrossPackageExampleSubclass.class, "staticPrivateField_Child", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
illegalAccessExceptionThrown = false;
try {
superclassLookup.findStaticGetter(CrossPackageExampleSubclass.class, "staticPrivateField_Child", 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_Private_CrossPackage_InnerClass_Level2.
/**
* Negative test : findSetter, findGetter test using private fields of an inner classes (level 2 deep) where the
* lookup class is the top outer class belonging to a different package.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Private_CrossPackage_InnerClass_Level2() throws Throwable {
Lookup publicLookup = PackageExamples.getLookup();
boolean illegalAccessExceptionThrown = false;
try {
publicLookup.findSetter(SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2.class, "nonStaticPrivateField_Inner2", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
illegalAccessExceptionThrown = false;
try {
publicLookup.findGetter(SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2.class, "nonStaticPrivateField_Inner2", 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_Static_SamePackage_SubclassLookup.
/**
* Negative test : findSetter, findGetter test using a Lookup whose lookup class is a sub-class
* and lookup fields are public static fields belonging to the super-class of the lookup class under the same package as
* the lookup class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Public_Static_SamePackage_SubclassLookup() throws Throwable {
Lookup subclassLookup = SamePackageExampleSubclass.getLookup();
boolean illegalAccessExceptionThrown = false;
try {
subclassLookup.findSetter(SamePackageExample.class, "staticPublicField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
// make sure we get access exception when trying to access a static field with findGetter/findSetter
if (illegalAccessExceptionThrown == false) {
Assert.fail("Illegal access to static public field given to findSetter/findGetter");
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
}
use of java.lang.invoke.MethodHandles.Lookup in project openj9 by eclipse.
the class Find_InvokeTracker method test_GetterSetter_Public_SamePackage_InnerClasse_Nested_Level12.
/**
* findSetter, findGetter test using public fields of a second level inner class
* where the lookup class is the first level inner class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Public_SamePackage_InnerClasse_Nested_Level12() throws Throwable {
SamePackageExample spe = new SamePackageExample();
SamePackageInnerClass spe_inner1 = spe.new SamePackageInnerClass();
Lookup publicLookup = spe_inner1.getLookup();
MethodHandle mhSetter = publicLookup.findSetter(SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2.class, "nonStaticPublicField_Inner2", int.class);
MethodHandle mhGetter = publicLookup.findGetter(SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2.class, "nonStaticPublicField_Inner2", int.class);
SamePackageExample.SamePackageInnerClass.SamePackageInnerClass_Nested_Level2 g = ((new SamePackageExample()).new SamePackageInnerClass()).new SamePackageInnerClass_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_Protected_CrossPackage.
/*protected fields ( cross package )*/
/**
* findSetter, findGetter tests involving protected fields of a class belonging to a different package than the Lookup class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Protected_CrossPackage() throws Throwable {
Lookup publicLookup = MethodHandles.lookup();
boolean illegalAccessExceptionThrown = false;
try {
publicLookup.findSetter(PackageExamples.class, "nonStaticProtectedField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
illegalAccessExceptionThrown = false;
try {
publicLookup.findGetter(PackageExamples.class, "nonStaticProtectedField", int.class);
} catch (IllegalAccessException e) {
illegalAccessExceptionThrown = true;
}
AssertJUnit.assertTrue(illegalAccessExceptionThrown);
}
Aggregations