Catch InaccessibleObjectException next to IllegalAccessException

Closes gh-35190
This commit is contained in:
Juergen Hoeller
2025-07-11 22:44:11 +02:00
parent ba6166a02d
commit 4277682a5c
10 changed files with 21 additions and 13 deletions
@@ -17,6 +17,7 @@
package org.springframework.beans;
import java.lang.reflect.Field;
import java.lang.reflect.InaccessibleObjectException;
import java.util.HashMap;
import java.util.Map;
@@ -144,7 +145,7 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
ReflectionUtils.makeAccessible(this.field);
return this.field.get(getWrappedInstance());
}
catch (IllegalAccessException ex) {
catch (IllegalAccessException | InaccessibleObjectException ex) {
throw new InvalidPropertyException(getWrappedClass(),
this.field.getName(), "Field is not accessible", ex);
}
@@ -156,7 +157,7 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
ReflectionUtils.makeAccessible(this.field);
this.field.set(getWrappedInstance(), value);
}
catch (IllegalAccessException ex) {
catch (IllegalAccessException | InaccessibleObjectException ex) {
throw new InvalidPropertyException(getWrappedClass(), this.field.getName(),
"Field is not accessible", ex);
}
@@ -17,6 +17,7 @@
package org.springframework.beans.factory.support;
import java.lang.reflect.Constructor;
import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.function.Supplier;
@@ -184,7 +185,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
"Illegal arguments to factory method '" + factoryMethod.getName() + "'; " +
"args: " + StringUtils.arrayToCommaDelimitedString(args), ex);
}
catch (IllegalAccessException ex) {
catch (IllegalAccessException | InaccessibleObjectException ex) {
throw new BeanInstantiationException(factoryMethod,
"Cannot access factory method '" + factoryMethod.getName() + "'; is it public?", ex);
}