-
Enhancement
-
Resolution: Unresolved
-
P5
-
None
-
6
-
x86
-
linux
A DESCRIPTION OF THE REQUEST :
Could you please add a new method forceGet(Object) or extend get with get(Object obj, boolean force). Implementation:
public Object get(Object obj, boolean force) {
return get(obj,false);
}
public Object get(Object obj, boolean force) {
if (force) {
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkPermission(new ReflectPermission("suppressAccessChecks"));
}
return getFieldAccessor(obj,force).get(obj);
}
private FieldAccessor getFieldAccessor(Object obj) throws IllegalAccessException {
return getFieldAccessor(obj, false);
}
private FieldAccessor getFieldAccessor(Object obj, boolean force) throws IllegalAccessException {
if (force == false) force = flag;
doSecurityCheck(obj);
boolean flag = override;
FieldAccessor fieldaccessor = flag ? overrideFieldAccessor : fieldAccessor;
return fieldaccessor == null ? acquireFieldAccessor(force) : fieldaccessor;
}
This streamlines the access process.
JUSTIFICATION :
If you wanted to access a restricted object using the field.get method, you would have to
setAccessible(true); and then reset it again. A simple addition (or an overloaded method), would remove the need to make numerous access checks. This modification still checks revelent permssions and upholds the specification.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Object obj = field.get(var,true);
ACTUAL -
You have to use the cumbersome:
field.setAccessible(true);
Object obj = field.get(var);
field.setAccessible(false);
Could you please add a new method forceGet(Object) or extend get with get(Object obj, boolean force). Implementation:
public Object get(Object obj, boolean force) {
return get(obj,false);
}
public Object get(Object obj, boolean force) {
if (force) {
SecurityManager securitymanager = System.getSecurityManager();
if(securitymanager != null)
securitymanager.checkPermission(new ReflectPermission("suppressAccessChecks"));
}
return getFieldAccessor(obj,force).get(obj);
}
private FieldAccessor getFieldAccessor(Object obj) throws IllegalAccessException {
return getFieldAccessor(obj, false);
}
private FieldAccessor getFieldAccessor(Object obj, boolean force) throws IllegalAccessException {
if (force == false) force = flag;
doSecurityCheck(obj);
boolean flag = override;
FieldAccessor fieldaccessor = flag ? overrideFieldAccessor : fieldAccessor;
return fieldaccessor == null ? acquireFieldAccessor(force) : fieldaccessor;
}
This streamlines the access process.
JUSTIFICATION :
If you wanted to access a restricted object using the field.get method, you would have to
setAccessible(true); and then reset it again. A simple addition (or an overloaded method), would remove the need to make numerous access checks. This modification still checks revelent permssions and upholds the specification.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Object obj = field.get(var,true);
ACTUAL -
You have to use the cumbersome:
field.setAccessible(true);
Object obj = field.get(var);
field.setAccessible(false);