HHH-5289 remove unnecessary security checks in property accessors

Conflicts:
	hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java
	hibernate-entitymanager/src/main/java/org/hibernate/jpa/event/internal/jpa/CallbackProcessorImpl.java
	hibernate-entitymanager/src/main/java/org/hibernate/jpa/event/internal/jpa/LegacyCallbackProcessor.java
	hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/metamodel/MetadataContext.java
This commit is contained in:
Brett Meyer 2014-01-10 16:05:22 -05:00
parent 4a57b45958
commit de91d9b2ca
9 changed files with 35 additions and 57 deletions

View File

@ -69,9 +69,7 @@ public class BeanValidationIntegrator implements Integrator {
final Class activatorClass = BeanValidationIntegrator.class.getClassLoader().loadClass( ACTIVATOR_CLASS_NAME );
try {
final Method validateMethod = activatorClass.getMethod( VALIDATE_SUPPLIED_FACTORY_METHOD_NAME, Object.class );
if ( ! validateMethod.isAccessible() ) {
validateMethod.setAccessible( true );
}
try {
validateMethod.invoke( null, object );
}

View File

@ -302,9 +302,7 @@ public final class ReflectHelper {
try {
Constructor constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
if ( !isPublic( clazz, constructor ) ) {
constructor.setAccessible( true );
}
return constructor;
}
catch ( NoSuchMethodException nme ) {
@ -362,9 +360,7 @@ public final class ReflectHelper {
}
}
if ( found ) {
if ( !isPublic( clazz, constructor ) ) {
constructor.setAccessible( true );
}
return constructor;
}
}

View File

@ -266,7 +266,7 @@ public class BasicPropertyAccessor implements PropertyAccessor {
Method method = setterMethod(theClass, propertyName);
if (method!=null) {
if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true);
method.setAccessible(true);
return new BasicSetter(theClass, method, propertyName);
}
else {
@ -331,9 +331,7 @@ public class BasicPropertyAccessor implements PropertyAccessor {
Method method = getterMethod(theClass, propertyName);
if (method!=null) {
if ( !ReflectHelper.isPublic( theClass, method ) ) {
method.setAccessible(true);
}
return new BasicGetter(theClass, method, propertyName);
}
else {

View File

@ -173,7 +173,7 @@ public class DirectPropertyAccessor implements PropertyAccessor {
catch (NoSuchFieldException nsfe) {
field = getField( clazz, clazz.getSuperclass(), name );
}
if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
field.setAccessible(true);
return field;
}
@ -188,7 +188,7 @@ public class DirectPropertyAccessor implements PropertyAccessor {
catch (NoSuchFieldException nsfe) {
field = getField( root, clazz.getSuperclass(), name );
}
if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
field.setAccessible(true);
return field;
}

View File

@ -192,9 +192,7 @@ public class JavassistLazyInitializer extends BasicLazyInitializer implements Me
returnValue = thisMethod.invoke( target, args );
}
else {
if ( !thisMethod.isAccessible() ) {
thisMethod.setAccessible( true );
}
returnValue = thisMethod.invoke( target, args );
}

View File

@ -135,16 +135,13 @@ public class ComponentTuplizerFactory implements Serializable {
Constructor<? extends ComponentTuplizer> constructor = null;
try {
constructor = clazz.getDeclaredConstructor( COMPONENT_TUP_CTOR_SIG );
if ( ! ReflectHelper.isPublic( constructor ) ) {
try {
// found a constructor, but it was not publicly accessible so try to request accessibility
constructor.setAccessible( true );
}
catch ( SecurityException e ) {
constructor = null;
}
}
}
catch ( NoSuchMethodException ignore ) {
}

View File

@ -227,16 +227,13 @@ public class EntityTuplizerFactory implements Serializable {
Constructor<? extends EntityTuplizer> constructor = null;
try {
constructor = clazz.getDeclaredConstructor( constructorArgs );
if ( ! ReflectHelper.isPublic( constructor ) ) {
try {
// found a constructor, but it was not publicly accessible so try to request accessibility
constructor.setAccessible( true );
}
catch ( SecurityException e ) {
constructor = null;
}
}
}
catch ( NoSuchMethodException ignore ) {
}

View File

@ -408,10 +408,8 @@ class MetadataContext {
? metamodelClass.getField( name )
: metamodelClass.getDeclaredField( name );
try {
if ( ! field.isAccessible() ) {
// should be public anyway, but to be sure...
field.setAccessible( true );
}
field.set( null, attribute );
}
catch ( IllegalAccessException e ) {

View File

@ -83,7 +83,6 @@ public class TestClassMetadata {
}
private void ensureAccessibility(Method method) {
if ( !method.isAccessible() ) {
try {
method.setAccessible( true );
}
@ -91,7 +90,6 @@ public class TestClassMetadata {
// ignore for now
}
}
}
private void addAfterClassOnceCallback(Method method) {
if ( afterClassOnceMethods == null ) {
@ -141,7 +139,6 @@ public class TestClassMetadata {
)
);
}
if ( !method.isAccessible() ) {
try {
method.setAccessible( true );
}
@ -153,7 +150,6 @@ public class TestClassMetadata {
);
}
}
}
private static enum CallbackType {
BEFORE_CLASS_ONCE( BeforeClassOnce.class ),