diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java index b6c899f1090..eae77b953ad 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java @@ -16,6 +16,7 @@ package org.springframework.aop.aspectj; +import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import org.springframework.aop.framework.AopConfigException; @@ -66,7 +67,7 @@ public class SimpleAspectInstanceFactory implements AspectInstanceFactory { throw new AopConfigException( "Unable to instantiate aspect class: " + this.aspectClass.getName(), ex); } - catch (IllegalAccessException ex) { + catch (IllegalAccessException | InaccessibleObjectException ex) { throw new AopConfigException( "Could not access aspect constructor: " + this.aspectClass.getName(), ex); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java index c76620fe7ee..3d6c20a5eae 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java @@ -16,6 +16,7 @@ package org.springframework.aop.support; +import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -367,7 +368,7 @@ public abstract class AopUtils { throw new AopInvocationException("AOP configuration seems to be invalid: tried calling method [" + method + "] on target [" + target + "]", ex); } - catch (IllegalAccessException ex) { + catch (IllegalAccessException | InaccessibleObjectException ex) { throw new AopInvocationException("Could not access method [" + method + "]", ex); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java b/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java index 57ecf6baec2..53b0efe01c6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java @@ -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); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java index d473c7bfbd1..e34d1780df6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java @@ -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); } diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java index 098892368d9..4454c084e4c 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java @@ -16,6 +16,7 @@ package org.springframework.context.event; +import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -374,8 +375,8 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe return null; } - ReflectionUtils.makeAccessible(this.method); try { + ReflectionUtils.makeAccessible(this.method); if (KotlinDetector.isSuspendingFunction(this.method)) { return CoroutinesUtils.invokeSuspendingFunction(this.method, bean, args); } @@ -385,7 +386,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe assertTargetBean(this.method, bean, args); throw new IllegalStateException(getInvocationErrorMessage(bean, ex.getMessage(), args), ex); } - catch (IllegalAccessException ex) { + catch (IllegalAccessException | InaccessibleObjectException ex) { throw new IllegalStateException(getInvocationErrorMessage(bean, ex.getMessage(), args), ex); } catch (InvocationTargetException ex) { diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java index 814b3831708..7e85fe14b93 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java @@ -16,6 +16,7 @@ package org.springframework.scheduling.annotation; +import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; @@ -173,7 +174,7 @@ abstract class ScheduledAnnotationReactiveSupport { "Cannot obtain a Publisher-convertible value from the @Scheduled reactive method", ex.getTargetException()); } - catch (IllegalAccessException ex) { + catch (IllegalAccessException | InaccessibleObjectException ex) { throw new IllegalArgumentException( "Cannot obtain a Publisher-convertible value from the @Scheduled reactive method", ex); } diff --git a/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java b/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java index da9abd32b9f..49a8a5ea0f7 100644 --- a/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java +++ b/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java @@ -17,6 +17,7 @@ package org.springframework.scripting.groovy; import java.io.IOException; +import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import groovy.lang.GroovyClassLoader; @@ -341,7 +342,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea throw new ScriptCompilationException( scriptSource, "Unable to instantiate Groovy script class: " + scriptClass.getName(), ex); } - catch (IllegalAccessException ex) { + catch (IllegalAccessException | InaccessibleObjectException ex) { throw new ScriptCompilationException( scriptSource, "Could not access Groovy script constructor: " + scriptClass.getName(), ex); } diff --git a/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java b/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java index 6dbc468c696..ff4d20998e4 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java @@ -17,6 +17,7 @@ package org.springframework.scripting.support; import java.io.IOException; +import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import javax.script.Invocable; @@ -172,7 +173,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar throw new ScriptCompilationException( scriptSource, "Unable to instantiate script class: " + scriptClass.getName(), ex); } - catch (IllegalAccessException ex) { + catch (IllegalAccessException | InaccessibleObjectException ex) { throw new ScriptCompilationException( scriptSource, "Could not access script constructor: " + scriptClass.getName(), ex); } diff --git a/spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java b/spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java index 22b1fa92372..929ff149922 100644 --- a/spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java +++ b/spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java @@ -17,6 +17,7 @@ package org.springframework.util; import java.io.Serializable; +import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -305,7 +306,7 @@ public class AutoPopulatingList implements List, Serializable { throw new ElementInstantiationException( "Unable to instantiate element class: " + this.elementClass.getName(), ex); } - catch (IllegalAccessException ex) { + catch (IllegalAccessException | InaccessibleObjectException ex) { throw new ElementInstantiationException( "Could not access element constructor: " + this.elementClass.getName(), ex); } diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandler.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandler.java index 1b212ff919a..298e5c80497 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandler.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandler.java @@ -17,7 +17,6 @@ package org.springframework.test.context.bean.override.convention; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Objects; @@ -58,7 +57,7 @@ final class TestBeanOverrideHandler extends BeanOverrideHandler { ReflectionUtils.makeAccessible(this.factoryMethod); return this.factoryMethod.invoke(null); } - catch (IllegalAccessException | InvocationTargetException ex) { + catch (Throwable ex) { throw new IllegalStateException( "Failed to invoke @TestBean factory method: " + this.factoryMethod, ex); }