5109N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 5109N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5109N/A * This code is free software; you can redistribute it and/or modify it 5109N/A * under the terms of the GNU General Public License version 2 only, as 5109N/A * published by the Free Software Foundation. Oracle designates this 5109N/A * particular file as subject to the "Classpath" exception as provided 5109N/A * by Oracle in the LICENSE file that accompanied this code. 5109N/A * This code is distributed in the hope that it will be useful, but WITHOUT 5109N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5109N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5109N/A * version 2 for more details (a copy is included in the LICENSE file that 5109N/A * You should have received a copy of the GNU General Public License version 5109N/A * 2 along with this work; if not, write to the Free Software Foundation, 5109N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5109N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5109N/A * or visit www.oracle.com if you need additional information or have any 5109N/A * @summary test access checking by java.lang.invoke.MethodHandles.Lookup 5109N/A * @build test.java.lang.invoke.AccessControlTest_subpkg.Acquaintance_remote 5109N/A * Test many combinations of Lookup access and cross-class lookupStatic. 5109N/A /** Simulate all assertions in the spec. for Lookup.toString. */ 5109N/A /** Simulate all assertions from the spec. for Lookup.in: 5109N/A * Creates a lookup on the specified new lookup class. 5109N/A * [A1] The resulting object will report the specified 5109N/A * class as its own {@link #lookupClass lookupClass}. 5109N/A * [A2] However, the resulting {@code Lookup} object is guaranteed 5109N/A * to have no more access capabilities than the original. 5109N/A * In particular, access capabilities can be lost as follows:<ul> 5109N/A * <li>[A3] If the new lookup class differs from the old one, 5109N/A * protected members will not be accessible by virtue of inheritance. 5109N/A * (Protected members may continue to be accessible because of package sharing.) 5109N/A * <li>[A4] If the new lookup class is in a different package 5109N/A * than the old one, protected and default (package) members will not be accessible. 5109N/A * <li>[A5] If the new lookup class is not within the same package member 5109N/A * as the old one, private members will not be accessible. 5109N/A * <li>[A6] If the new lookup class is not accessible to the old lookup class, 5109N/A * using the original access modes, 5109N/A * then no members, not even public members, will be accessible. 5109N/A * [A7] (In all other cases, public members will continue to be accessible.) 5109N/A * Other than the above cases, the new lookup will have the same 5109N/A * access capabilities as the original. [A8] 5109N/A // Different package and no access to c2; lose all access. 5109N/A // Different package; lose PACKAGE and lower access. 5109N/A // Different top-level class. Lose PRIVATE and lower access. 5109N/A assert((
m1 |
m2) ==
m1);
// [A2] (no elevation of access) 5109N/A /** Predict the success or failure of accessing this method. */ 5109N/A // privacy is strictly enforced on lookups 5109N/A // protected access is sometimes allowed 5109N/A m2 |=
PUBLIC;
// from a subclass, it acts like a public method also 5109N/A assert((
m1 |
m2) ==
m1);
// [A2] (no elevation of access) 5109N/A // make initial set of lookup test cases 5109N/A // Try to access target method from various contexts. 5109N/A // return "self", "sibling", "nestmate", etc. 5109N/A /** Return one of the ACCESS_CASES. */ 5109N/A// This guy tests access from outside the package: 5109N/Apublic class Acquaintance_remote { 5109N/A public static Lookup[] lookups() { ...