mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-10 05:04:52 +00:00
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:
parent
4a57b45958
commit
de91d9b2ca
@ -69,9 +69,7 @@ public static void validateFactory(Object object) {
|
||||
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 );
|
||||
}
|
||||
validateMethod.setAccessible( true );
|
||||
try {
|
||||
validateMethod.invoke( null, object );
|
||||
}
|
||||
|
@ -302,9 +302,7 @@ public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotF
|
||||
|
||||
try {
|
||||
Constructor constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
|
||||
if ( !isPublic( clazz, constructor ) ) {
|
||||
constructor.setAccessible( true );
|
||||
}
|
||||
constructor.setAccessible( true );
|
||||
return constructor;
|
||||
}
|
||||
catch ( NoSuchMethodException nme ) {
|
||||
@ -362,9 +360,7 @@ public static Constructor getConstructor(Class clazz, Type[] types) throws Prope
|
||||
}
|
||||
}
|
||||
if ( found ) {
|
||||
if ( !isPublic( clazz, constructor ) ) {
|
||||
constructor.setAccessible( true );
|
||||
}
|
||||
constructor.setAccessible( true );
|
||||
return constructor;
|
||||
}
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ private static BasicSetter getSetterOrNull(Class theClass, String propertyName)
|
||||
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 @@ private static BasicGetter getGetterOrNull(Class theClass, String propertyName)
|
||||
Method method = getterMethod(theClass, propertyName);
|
||||
|
||||
if (method!=null) {
|
||||
if ( !ReflectHelper.isPublic( theClass, method ) ) {
|
||||
method.setAccessible(true);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return new BasicGetter(theClass, method, propertyName);
|
||||
}
|
||||
else {
|
||||
|
@ -173,7 +173,7 @@ private static Field getField(Class clazz, String name) throws PropertyNotFoundE
|
||||
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 @@ private static Field getField(Class root, Class clazz, String name) throws Prope
|
||||
catch (NoSuchFieldException nsfe) {
|
||||
field = getField( root, clazz.getSuperclass(), name );
|
||||
}
|
||||
if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
|
@ -192,9 +192,7 @@ public Object invoke(
|
||||
returnValue = thisMethod.invoke( target, args );
|
||||
}
|
||||
else {
|
||||
if ( !thisMethod.isAccessible() ) {
|
||||
thisMethod.setAccessible( true );
|
||||
}
|
||||
thisMethod.setAccessible( true );
|
||||
returnValue = thisMethod.invoke( target, args );
|
||||
}
|
||||
|
||||
|
@ -135,14 +135,11 @@ private Constructor<? extends ComponentTuplizer> getProperConstructor(Class<? ex
|
||||
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;
|
||||
}
|
||||
try {
|
||||
constructor.setAccessible( true );
|
||||
}
|
||||
catch ( SecurityException e ) {
|
||||
constructor = null;
|
||||
}
|
||||
}
|
||||
catch ( NoSuchMethodException ignore ) {
|
||||
@ -157,4 +154,4 @@ private static Map<EntityMode,Class<? extends ComponentTuplizer>> buildBaseMappi
|
||||
map.put( EntityMode.MAP, DynamicMapComponentTuplizer.class );
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -227,14 +227,11 @@ private Constructor<? extends EntityTuplizer> getProperConstructor(
|
||||
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;
|
||||
}
|
||||
try {
|
||||
constructor.setAccessible( true );
|
||||
}
|
||||
catch ( SecurityException e ) {
|
||||
constructor = null;
|
||||
}
|
||||
}
|
||||
catch ( NoSuchMethodException ignore ) {
|
||||
|
@ -408,10 +408,8 @@ private <X> void registerAttribute(Class metamodelClass, Attribute<X, ?> attribu
|
||||
? metamodelClass.getField( name )
|
||||
: metamodelClass.getDeclaredField( name );
|
||||
try {
|
||||
if ( ! field.isAccessible() ) {
|
||||
// should be public anyway, but to be sure...
|
||||
field.setAccessible( true );
|
||||
}
|
||||
// should be public anyway, but to be sure...
|
||||
field.setAccessible( true );
|
||||
field.set( null, attribute );
|
||||
}
|
||||
catch ( IllegalAccessException e ) {
|
||||
|
@ -83,13 +83,11 @@ private void addBeforeClassOnceCallback(Method method) {
|
||||
}
|
||||
|
||||
private void ensureAccessibility(Method method) {
|
||||
if ( !method.isAccessible() ) {
|
||||
try {
|
||||
method.setAccessible( true );
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
// ignore for now
|
||||
}
|
||||
try {
|
||||
method.setAccessible( true );
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
// ignore for now
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,17 +139,15 @@ private void validateCallbackMethod(Method method, CallbackType type, List<Throw
|
||||
)
|
||||
);
|
||||
}
|
||||
if ( !method.isAccessible() ) {
|
||||
try {
|
||||
method.setAccessible( true );
|
||||
}
|
||||
catch (Exception e) {
|
||||
errors.add(
|
||||
new InvalidMethodForAnnotationException(
|
||||
type.buildTypeMarker() + " attached to inaccessible method and unable to make accessible"
|
||||
)
|
||||
);
|
||||
}
|
||||
try {
|
||||
method.setAccessible( true );
|
||||
}
|
||||
catch (Exception e) {
|
||||
errors.add(
|
||||
new InvalidMethodForAnnotationException(
|
||||
type.buildTypeMarker() + " attached to inaccessible method and unable to make accessible"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user