Java Code Examples for sun.invoke.util.VerifyAccess#isMemberAccessible()
The following examples show how to use
sun.invoke.util.VerifyAccess#isMemberAccessible() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodHandles.java From jdk-1.7-annotated with Apache License 2.0 | 5 votes |
void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 2
Source File: MemberName.java From jdk-1.7-annotated with Apache License 2.0 | 4 votes |
/** Utility method to query whether this member is accessible from a given lookup class. */ public boolean isAccessibleFrom(Class<?> lookupClass) { return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, lookupClass, ALL_ACCESS|MethodHandles.Lookup.PACKAGE); }
Example 3
Source File: MemberName.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** Utility method to query whether this member is accessible from a given lookup class. */ public boolean isAccessibleFrom(Class<?> lookupClass) { return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, lookupClass, ALL_ACCESS|MethodHandles.Lookup.PACKAGE); }
Example 4
Source File: MethodHandles.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 5
Source File: MemberName.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** Utility method to query whether this member is accessible from a given lookup class. */ public boolean isAccessibleFrom(Class<?> lookupClass) { return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, lookupClass, ALL_ACCESS|MethodHandles.Lookup.PACKAGE); }
Example 6
Source File: MemberName.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** Utility method to query whether this member is accessible from a given lookup class. */ public boolean isAccessibleFrom(Class<?> lookupClass) { int mode = (ALL_ACCESS|MethodHandles.Lookup.PACKAGE|MethodHandles.Lookup.MODULE); return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, lookupClass, mode); }
Example 7
Source File: MemberName.java From Bytecoder with Apache License 2.0 | 4 votes |
/** Utility method to query whether this member is accessible from a given lookup class. */ public boolean isAccessibleFrom(Class<?> lookupClass) { int mode = (ALL_ACCESS|MethodHandles.Lookup.PACKAGE|MethodHandles.Lookup.MODULE); return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, lookupClass, null, mode); }
Example 8
Source File: MethodHandles.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 9
Source File: MemberName.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** Utility method to query whether this member is accessible from a given lookup class. */ public boolean isAccessibleFrom(Class<?> lookupClass) { return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, lookupClass, ALL_ACCESS|MethodHandles.Lookup.PACKAGE); }
Example 10
Source File: MethodHandles.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 11
Source File: MethodHandles.java From hottub with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 12
Source File: MemberName.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** Utility method to query whether this member is accessible from a given lookup class. */ public boolean isAccessibleFrom(Class<?> lookupClass) { return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, lookupClass, ALL_ACCESS|MethodHandles.Lookup.PACKAGE); }
Example 13
Source File: MethodHandles.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 14
Source File: MethodHandles.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 15
Source File: MethodHandles.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 16
Source File: MemberName.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** Utility method to query whether this member is accessible from a given lookup class. */ public boolean isAccessibleFrom(Class<?> lookupClass) { return VerifyAccess.isMemberAccessible(this.getDeclaringClass(), this.getDeclaringClass(), flags, lookupClass, ALL_ACCESS|MethodHandles.Lookup.PACKAGE); }
Example 17
Source File: MethodHandles.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 18
Source File: MethodHandles.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }
Example 19
Source File: MethodHandles.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(Class<?> refc, Class<?> defc, int mods, String methName) throws IllegalAccessException { int allowedModes = this.allowedModes; if (Modifier.isProtected(mods) && defc == Object.class && "clone".equals(methName) && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && Modifier.isConstructor(mods)) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, defc, mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(defc, lookupClass())) return; } throwMakeAccessException(accessFailedMessage(refc, defc, mods), this); }
Example 20
Source File: MethodHandles.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** Check public/protected/private bits on the symbolic reference class and its member. */ void checkAccess(byte refKind, Class<?> refc, MemberName m) throws IllegalAccessException { assert(m.referenceKindIsConsistentWith(refKind) && MethodHandleNatives.refKindIsValid(refKind) && (MethodHandleNatives.refKindIsField(refKind) == m.isField())); int allowedModes = this.allowedModes; if (allowedModes == TRUSTED) return; int mods = m.getModifiers(); if (Modifier.isProtected(mods) && refKind == REF_invokeVirtual && m.getDeclaringClass() == Object.class && m.getName().equals("clone") && refc.isArray()) { // The JVM does this hack also. // (See ClassVerifier::verify_invoke_instructions // and LinkResolver::check_method_accessability.) // Because the JVM does not allow separate methods on array types, // there is no separate method for int[].clone. // All arrays simply inherit Object.clone. // But for access checking logic, we make Object.clone // (normally protected) appear to be public. // Later on, when the DirectMethodHandle is created, // its leading argument will be restricted to the // requested array type. // N.B. The return type is not adjusted, because // that is *not* the bytecode behavior. mods ^= Modifier.PROTECTED | Modifier.PUBLIC; } if (Modifier.isProtected(mods) && refKind == REF_newInvokeSpecial) { // cannot "new" a protected ctor in a different package mods ^= Modifier.PROTECTED; } if (Modifier.isFinal(mods) && MethodHandleNatives.refKindIsSetter(refKind)) throw m.makeAccessException("unexpected set of a final field", this); if (Modifier.isPublic(mods) && Modifier.isPublic(refc.getModifiers()) && allowedModes != 0) return; // common case int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0) { if (VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), mods, lookupClass(), allowedModes)) return; } else { // Protected members can also be checked as if they were package-private. if ((requestedModes & PROTECTED) != 0 && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) return; } throw m.makeAccessException(accessFailedMessage(refc, m), this); }