1 /*
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
224 if (cld != THIS_LOADER) s += "/loader#"+numberOf(cld);
225 return s;
226 }
227
228 /** Predict the success or failure of accessing this method. */
229 public boolean willAccess(Method m) {
230 Class<?> c1 = lookupClass();
231 Class<?> c2 = m.getDeclaringClass();
232
233 // publicLookup has access to all public types/members of types in unnamed modules
234 if ((lookupModes & UNCONDITIONAL) != 0
235 && (lookupModes & PUBLIC) != 0
236 && !c2.getModule().isNamed()
237 && Modifier.isPublic(c2.getModifiers())
238 && Modifier.isPublic(m.getModifiers()))
239 return true;
240
241 LookupCase lc = this.in(c2);
242 int m1 = lc.lookupModes();
243 int m2 = fixMods(m.getModifiers());
244 // privacy is strictly enforced on lookups
245 if (c1 != c2) m1 &= ~PRIVATE;
246 // protected access is sometimes allowed
247 if ((m2 & PROTECTED) != 0) {
248 int prev = m2;
249 m2 |= PACKAGE; // it acts like a package method also
250 if ((lookupModes() & PROTECTED) != 0 &&
251 c2.isAssignableFrom(c1))
252 m2 |= PUBLIC; // from a subclass, it acts like a public method also
253 }
254 if (verbosity >= 2)
255 System.out.println(this+" willAccess "+lc+" m1="+m1+" m2="+m2+" => "+((m2 & m1) != 0));
256 return (m2 & m1) != 0;
257 }
258
259 /** Predict the success or failure of accessing this class. */
260 public boolean willAccessClass(Class<?> c2, boolean load) {
261 Class<?> c1 = lookupClass();
262 if (load && c2.getClassLoader() != null) {
263 if (c1.getClassLoader() == null) {
264 // not visible
265 return false;
266 }
267 }
268
269 // publicLookup has access to all public types/members of types in unnamed modules
270 if ((lookupModes & UNCONDITIONAL) != 0
271 && (lookupModes & PUBLIC) != 0
272 && (!c2.getModule().isNamed())
273 && Modifier.isPublic(c2.getModifiers()))
274 return true;
275
|
1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
224 if (cld != THIS_LOADER) s += "/loader#"+numberOf(cld);
225 return s;
226 }
227
228 /** Predict the success or failure of accessing this method. */
229 public boolean willAccess(Method m) {
230 Class<?> c1 = lookupClass();
231 Class<?> c2 = m.getDeclaringClass();
232
233 // publicLookup has access to all public types/members of types in unnamed modules
234 if ((lookupModes & UNCONDITIONAL) != 0
235 && (lookupModes & PUBLIC) != 0
236 && !c2.getModule().isNamed()
237 && Modifier.isPublic(c2.getModifiers())
238 && Modifier.isPublic(m.getModifiers()))
239 return true;
240
241 LookupCase lc = this.in(c2);
242 int m1 = lc.lookupModes();
243 int m2 = fixMods(m.getModifiers());
244 // allow private lookup on nestmates. Otherwise, privacy is strictly enforced
245 if (c1 != c2 && ((m2 & PRIVATE) == 0 || !c1.isNestmateOf(c2))) {
246 m1 &= ~PRIVATE;
247 }
248 // protected access is sometimes allowed
249 if ((m2 & PROTECTED) != 0) {
250 int prev = m2;
251 m2 |= PACKAGE; // it acts like a package method also
252 if ((lookupModes() & PROTECTED) != 0 &&
253 c2.isAssignableFrom(c1))
254 m2 |= PUBLIC; // from a subclass, it acts like a public method also
255 }
256 if (verbosity >= 2)
257 System.out.format("%s willAccess %s m1=0x%h m2=0x%h => %s%n", this, lc, m1, m2, ((m2 & m1) != 0));
258 return (m2 & m1) != 0;
259 }
260
261 /** Predict the success or failure of accessing this class. */
262 public boolean willAccessClass(Class<?> c2, boolean load) {
263 Class<?> c1 = lookupClass();
264 if (load && c2.getClassLoader() != null) {
265 if (c1.getClassLoader() == null) {
266 // not visible
267 return false;
268 }
269 }
270
271 // publicLookup has access to all public types/members of types in unnamed modules
272 if ((lookupModes & UNCONDITIONAL) != 0
273 && (lookupModes & PUBLIC) != 0
274 && (!c2.getModule().isNamed())
275 && Modifier.isPublic(c2.getModifiers()))
276 return true;
277
|