< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2008, 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. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2008, 2018, 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. Oracle designates this
*** 2214,2247 **** if (Modifier.isProtected(mods)) return "member is protected"; return "member is private to package"; } - private static final boolean ALLOW_NESTMATE_ACCESS = false; - private void checkSpecialCaller(Class<?> specialCaller, Class<?> refc) throws IllegalAccessException { int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; if (!hasPrivateAccess() || (specialCaller != lookupClass() // ensure non-abstract methods in superinterfaces can be special-invoked ! && !(refc != null && refc.isInterface() && refc.isAssignableFrom(specialCaller)) ! && !(ALLOW_NESTMATE_ACCESS && ! VerifyAccess.isSamePackageMember(specialCaller, lookupClass())))) throw new MemberName(specialCaller). makeAccessException("no private access for invokespecial", this); } private boolean restrictProtectedReceiver(MemberName method) { // The accessing class only has the right to use a protected member // on itself or a subclass. Enforce that restriction, from JVMS 5.4.4, etc. if (!method.isProtected() || method.isStatic() || allowedModes == TRUSTED || method.getDeclaringClass() == lookupClass() ! || VerifyAccess.isSamePackage(method.getDeclaringClass(), lookupClass()) ! || (ALLOW_NESTMATE_ACCESS && ! VerifyAccess.isSamePackageMember(method.getDeclaringClass(), lookupClass()))) return false; return true; } private MethodHandle restrictReceiver(MemberName method, DirectMethodHandle mh, Class<?> caller) throws IllegalAccessException { assert(!method.isStatic()); --- 2214,2241 ---- if (Modifier.isProtected(mods)) return "member is protected"; return "member is private to package"; } private void checkSpecialCaller(Class<?> specialCaller, Class<?> refc) throws IllegalAccessException { int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; if (!hasPrivateAccess() || (specialCaller != lookupClass() // ensure non-abstract methods in superinterfaces can be special-invoked ! && !(refc != null && refc.isInterface() && refc.isAssignableFrom(specialCaller)))) throw new MemberName(specialCaller). makeAccessException("no private access for invokespecial", this); } private boolean restrictProtectedReceiver(MemberName method) { // The accessing class only has the right to use a protected member // on itself or a subclass. Enforce that restriction, from JVMS 5.4.4, etc. if (!method.isProtected() || method.isStatic() || allowedModes == TRUSTED || method.getDeclaringClass() == lookupClass() ! || VerifyAccess.isSamePackage(method.getDeclaringClass(), lookupClass())) return false; return true; } private MethodHandle restrictReceiver(MemberName method, DirectMethodHandle mh, Class<?> caller) throws IllegalAccessException { assert(!method.isStatic());
*** 2277,2286 **** --- 2271,2281 ---- } /** Common code for all methods; do not call directly except from immediately above. */ private MethodHandle getDirectMethodCommon(byte refKind, Class<?> refc, MemberName method, boolean checkSecurity, boolean doRestrict, Class<?> callerClass) throws IllegalAccessException { + checkMethod(refKind, refc, method); // Optionally check with the security manager; this isn't needed for unreflect* calls. if (checkSecurity) checkSecurityManager(refc, method); assert(!method.isMethodHandleInvoke());
*** 2289,2298 **** --- 2284,2294 ---- refc != lookupClass() && !refc.isInterface() && refc != lookupClass().getSuperclass() && refc.isAssignableFrom(lookupClass())) { assert(!method.getName().equals("<init>")); // not this code path + // Per JVMS 6.5, desc. of invokespecial instruction: // If the method is in a superclass of the LC, // and if our original search was above LC.super, // repeat the search (symbolic lookup) from LC.super // and continue with the direct superclass of that class,
< prev index next >