Search in sources :

Example 66 with Lookup

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

the class LookupInTests method testLookup_PublicNestedInnerClassLookup_Level2.

/**
 * 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 the top level outer class.
 * Basically we validate that a top level class C can access private members within a nested class C.D.E.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_PublicNestedInnerClassLookup_Level2() throws Throwable {
    Lookup inObj = samePackageExampleLookup.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 67 with Lookup

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

the class LookupInTests method testLookup_PublicNestedOuterClassLookup_Level2.

/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is a first level inner class on top of the old lookup class which is the second
 * level inner class. Basically we validate that a nested class C.D.E can access private members within
 * another nested class C.D.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_PublicNestedOuterClassLookup_Level2() throws Throwable {
    Lookup inObj = samePackageInnerClass_Nested_Level2Lookup.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 68 with Lookup

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

the class LookupInTests method testLookup_PrivateOuterClassLookup.

/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is a non-public outer class in the same Java source file as the old lookup class
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_PrivateOuterClassLookup() throws Throwable {
    Lookup inObj = localLookup.in(PackageClass.class);
    assertClassAndMode(inObj, PackageClass.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 69 with Lookup

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

the class LookupInTests method testLookup_ProtectedInnerClassLookup_CrossPackage.

/**
 * Validates access restrictions stored in a new Lookup object created from an old Lookup object
 * where the new lookup class is a protected 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_ProtectedInnerClassLookup_CrossPackage() throws Throwable {
    Lookup inObj = packageExamplesLookup.in(SamePackageInnerClass_Protected.class);
    assertClassAndMode(inObj, SamePackageInnerClass_Protected.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 70 with Lookup

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

the class LookupInTests method testLookup_SamePackageLookup_Subclass.

/**
 * Validates that, if a new lookup class differs from the old one, protected members will not be
 * accessible by virtue of inheritance. The test creates a new Lookup object from an old Lookup object
 * where the new Lookup class is a subclass of the original lookup class.
 * @throws Throwable
 */
@Test(groups = { "level.sanity" })
public void testLookup_SamePackageLookup_Subclass() throws Throwable {
    Lookup inObject = samePackageExampleLookup.in(SamePackageExampleSubclass.class);
    assertClassAndMode(inObject, SamePackageExampleSubclass.class, MODULE_PUBLIC_PACKAGE_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