Java Code Examples for java.lang.reflect.AccessibleObject.isAccessible()

The following are Jave code examples for showing how to use isAccessible() of the java.lang.reflect.AccessibleObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DroidTelescope   File: MemberUtils.java   View Source Code Vote up 6 votes
static boolean setAccessibleWorkaround(final AccessibleObject o) {
    if (o == null || o.isAccessible()) {
        return false;
    }
    final Member m = (Member) o;
    if (!o.isAccessible() && Modifier.isPublic(m.getModifiers()) && isPackageAccess(m
            .getDeclaringClass().getModifiers())) {
        try {
            o.setAccessible(true);
            return true;
        } catch (final SecurityException e) { // NOPMD
            // ignore in favor of subsequent IllegalAccessException
        }
    }
    return false;
}
 
Example 2
Project: whackpad   File: VMBridge_jdk13.java   View Source Code Vote up 6 votes
@Override
protected boolean tryToMakeAccessible(Object accessibleObject)
{
    if (!(accessibleObject instanceof AccessibleObject)) {
        return false;
    }
    AccessibleObject accessible = (AccessibleObject)accessibleObject;
    if (accessible.isAccessible()) {
        return true;
    }
    try {
        accessible.setAccessible(true);
    } catch (Exception ex) { }

    return accessible.isAccessible();
}
 
Example 3
Project: GitHub   File: TypeUtils.java   View Source Code Vote up 5 votes
static void setAccessible(AccessibleObject obj){
    if(!setAccessibleEnable){
        return;
    }
    if(obj.isAccessible()){
        return;
    }
    try{
        obj.setAccessible(true);
    } catch(AccessControlException error){
        setAccessibleEnable = false;
    }
}
 
Example 4
Project: HL4A   File: VMBridge_jdk15.java   View Source Code Vote up 5 votes
@Override
protected boolean tryToMakeAccessible(AccessibleObject accessible)
{
    if (accessible.isAccessible()) {
        return true;
    }
    try {
        accessible.setAccessible(true);
    } catch (Exception ex) { }

    return accessible.isAccessible();
}
 
Example 5
Project: lams   File: MemberUtils.java   View Source Code Vote up 5 votes
/**
 * XXX Default access superclass workaround
 *
 * When a public class has a default access superclass with public members,
 * these members are accessible. Calling them from compiled code works fine.
 * Unfortunately, on some JVMs, using reflection to invoke these members
 * seems to (wrongly) to prevent access even when the modifer is public.
 * Calling setAccessible(true) solves the problem but will only work from
 * sufficiently privileged code. Better workarounds would be gratefully
 * accepted.
 * @param o the AccessibleObject to set as accessible
 */
static void setAccessibleWorkaround(AccessibleObject o) {
    if (o == null || o.isAccessible()) {
        return;
    }
    Member m = (Member) o;
    if (Modifier.isPublic(m.getModifiers())
            && isPackageAccess(m.getDeclaringClass().getModifiers())) {
        try {
            o.setAccessible(true);
        } catch (SecurityException e) {
            // ignore in favor of subsequent IllegalAccessException
        }
    }
}
 
Example 6
Project: DroidPlugin   File: MemberUtils.java   View Source Code Vote up 5 votes
static boolean setAccessibleWorkaround(final AccessibleObject o) {
    if (o == null || o.isAccessible()) {
        return false;
    }
    final Member m = (Member) o;
    if (!o.isAccessible() && Modifier.isPublic(m.getModifiers()) && isPackageAccess(m.getDeclaringClass().getModifiers())) {
        try {
            o.setAccessible(true);
            return true;
        } catch (final SecurityException e) { // NOPMD
            // ignore in favor of subsequent IllegalAccessException
        }
    }
    return false;
}
 
Example 7
Project: boohee_v5.6   File: TypeUtils.java   View Source Code Vote up 5 votes
static void setAccessible(AccessibleObject obj) {
    if (setAccessibleEnable && !obj.isAccessible()) {
        try {
            obj.setAccessible(true);
        } catch (AccessControlException e) {
            setAccessibleEnable = false;
        }
    }
}
 
Example 8
Project: aws-sdk-java-v2   File: AbstractErrorUnmarshaller.java   View Source Code Vote up 5 votes
protected static void makeAccessible(AccessibleObject object) {
    if (!object.isAccessible()) {
        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
            object.setAccessible(true);
            return null;
        });
    }
}
 
Example 9
Project: uavstack   File: TypeUtils.java   View Source Code Vote up 5 votes
static void setAccessible(AccessibleObject obj) {
    if (!setAccessibleEnable) {
        return;
    }
    
    if (obj.isAccessible()) {
        return;
    }
    
    try {
        obj.setAccessible(true);
    } catch (AccessControlException error) {
        setAccessibleEnable = false;
    }
}
 
Example 10
Project: jaffa-framework   File: GraphMapping.java   View Source Code Vote up 5 votes
/** Returns the Field object, if available, or the setter Method, corresponding to the input dataFieldName.
 * @param dataFieldName the name of the data field.
 * @return the Field object, if available, or the setter Method, corresponding to the input dataFieldName.
 */
public AccessibleObject getDataMutator(String dataFieldName) {
    AccessibleObject accessibleObject = containsDataField(dataFieldName) ? elementMap.get(dataFieldName).getGraphField() : null;
    if (accessibleObject == null) {
        PropertyDescriptor pd = getDataFieldDescriptor(dataFieldName);
        if (pd != null) {
            accessibleObject = pd.getWriteMethod();
            if (!accessibleObject.isAccessible())
                accessibleObject.setAccessible(true);
        }
    }
    return accessibleObject;
}
 
Example 11
Project: AndHook   File: MemberUtils.java   View Source Code Vote up 5 votes
/**
 * XXX Default access superclass workaround
 * <p>
 * When a public class has a default access superclass with public members,
 * these members are accessible. Calling them from compiled code works fine.
 * Unfortunately, on some JVMs, using reflection to invoke these members
 * seems to (wrongly) prevent access even when the modifier is public.
 * Calling setAccessible(true) solves the problem but will only work from
 * sufficiently privileged code. Better workarounds would be gratefully
 * accepted.
 *
 * @param o the AccessibleObject to set as accessible
 */
static void setAccessibleWorkaround(AccessibleObject o) {
    if (o == null || o.isAccessible()) {
        return;
    }
    Member m = (Member) o;
    if (Modifier.isPublic(m.getModifiers())
            && isPackageAccess(m.getDeclaringClass().getModifiers())) {
        try {
            o.setAccessible(true);
        } catch (SecurityException e) { // NOPMD
            // ignore in favor of subsequent IllegalAccessException
        }
    }
}
 
Example 12
Project: springreplugin   File: ReflectUtils.java   View Source Code Vote up 4 votes
public static void setAccessible(AccessibleObject ao, boolean value) {
    if (ao.isAccessible() != value) {
        ao.setAccessible(value);
    }
}