Browse Source

Fix handling of protected visibility

Previously, InstanceSupplierCodeGenerator used reflection if the target
visibility is either protected or private, and use direct access if the
target visibility is public or package private.

The previous arrangement already assumed that the code is generateed in
the same package as the target type. This means that protected can be
used as well so this commit only use reflection if the target visibility
is private.

Closes gh-29253
pull/29282/head
Stephane Nicoll 2 years ago
parent
commit
9820e3341d
  1. 6
      spring-beans/src/main/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGenerator.java

6
spring-beans/src/main/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGenerator.java

@ -113,8 +113,7 @@ class InstanceSupplierCodeGenerator { @@ -113,8 +113,7 @@ class InstanceSupplierCodeGenerator {
.getUserClass(constructor.getDeclaringClass());
boolean dependsOnBean = ClassUtils.isInnerClass(declaringClass);
Visibility accessVisibility = getAccessVisibility(registeredBean, constructor);
if (accessVisibility == Visibility.PUBLIC
|| accessVisibility == Visibility.PACKAGE_PRIVATE) {
if (accessVisibility != Visibility.PRIVATE) {
return generateCodeForAccessibleConstructor(beanName, beanClass, constructor,
dependsOnBean, declaringClass);
}
@ -208,8 +207,7 @@ class InstanceSupplierCodeGenerator { @@ -208,8 +207,7 @@ class InstanceSupplierCodeGenerator {
.getUserClass(factoryMethod.getDeclaringClass());
boolean dependsOnBean = !Modifier.isStatic(factoryMethod.getModifiers());
Visibility accessVisibility = getAccessVisibility(registeredBean, factoryMethod);
if (accessVisibility == Visibility.PUBLIC
|| accessVisibility == Visibility.PACKAGE_PRIVATE) {
if (accessVisibility != Visibility.PRIVATE) {
return generateCodeForAccessibleFactoryMethod(beanName, beanClass, factoryMethod,
declaringClass, dependsOnBean);
}

Loading…
Cancel
Save