< prev index next >
test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 80,102 ****
MethodHandle mh = lookup.findStaticGetter(nonPublicType, "obj", Object.class);
Object obj = mh.invokeExact();
}
// Invoke MethodHandles.privateLookupIn with a reduced-power caller
public void testReducedAccessCallerSameModule() throws Throwable {
Lookup caller = MethodHandles.lookup().dropLookupMode(PACKAGE);
assertTrue((caller.lookupModes() & PRIVATE) == 0);
assertTrue((caller.lookupModes() & PACKAGE) == 0);
assertTrue((caller.lookupModes() & MODULE) != 0);
Lookup lookup = MethodHandles.privateLookupIn(nonPublicType, caller);
- assertTrue(lookup.lookupClass() == nonPublicType);
- assertTrue(lookup.hasPrivateAccess());
-
- // use it
- MethodHandle mh = lookup.findStaticGetter(nonPublicType, "obj", Object.class);
- Object obj = mh.invokeExact();
}
// Invoke MethodHandles.privateLookupIn with the public lookup as caller
@Test(expectedExceptions = {IllegalAccessException.class})
public void testPublicLookupSameModule() throws Exception {
--- 80,97 ----
MethodHandle mh = lookup.findStaticGetter(nonPublicType, "obj", Object.class);
Object obj = mh.invokeExact();
}
// Invoke MethodHandles.privateLookupIn with a reduced-power caller
+ @Test(expectedExceptions = {IllegalAccessException.class})
public void testReducedAccessCallerSameModule() throws Throwable {
Lookup caller = MethodHandles.lookup().dropLookupMode(PACKAGE);
assertTrue((caller.lookupModes() & PRIVATE) == 0);
assertTrue((caller.lookupModes() & PACKAGE) == 0);
assertTrue((caller.lookupModes() & MODULE) != 0);
Lookup lookup = MethodHandles.privateLookupIn(nonPublicType, caller);
}
// Invoke MethodHandles.privateLookupIn with the public lookup as caller
@Test(expectedExceptions = {IllegalAccessException.class})
public void testPublicLookupSameModule() throws Exception {
< prev index next >