Skip to content

Commit

Permalink
Merge branch '5.3.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
  • Loading branch information
jhoeller committed Nov 14, 2022
2 parents 28cd39a + ec3f59e commit 588a702
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
// Only allow URL attribute introspection, not content resolution
continue;
}
if (pd.getWriteMethod() == null && isInvalidReadOnlyPropertyType(pd.getPropertyType())) {
if (pd.getWriteMethod() == null && isInvalidReadOnlyPropertyType(pd.getPropertyType(), beanClass)) {
// Ignore read-only properties such as ClassLoader - no need to bind to those
continue;
}
Expand Down Expand Up @@ -320,7 +320,8 @@ private void introspectInterfaces(Class<?> beanClass, Class<?> currClass, Set<St
// GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
// against a declared read method, so we prefer read method descriptors here.
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
if (pd.getWriteMethod() == null && isInvalidReadOnlyPropertyType(pd.getPropertyType())) {
if (pd.getWriteMethod() == null &&
isInvalidReadOnlyPropertyType(pd.getPropertyType(), beanClass)) {
// Ignore read-only properties such as ClassLoader - no need to bind to those
continue;
}
Expand Down Expand Up @@ -353,7 +354,7 @@ private boolean isPlainAccessor(Method method) {
if (Modifier.isStatic(method.getModifiers()) ||
method.getDeclaringClass() == Object.class || method.getDeclaringClass() == Class.class ||
method.getParameterCount() > 0 || method.getReturnType() == void.class ||
isInvalidReadOnlyPropertyType(method.getReturnType())) {
isInvalidReadOnlyPropertyType(method.getReturnType(), method.getDeclaringClass())) {
return false;
}
try {
Expand All @@ -366,10 +367,11 @@ private boolean isPlainAccessor(Method method) {
}
}

private boolean isInvalidReadOnlyPropertyType(@Nullable Class<?> returnType) {
return (returnType != null && (AutoCloseable.class.isAssignableFrom(returnType) ||
ClassLoader.class.isAssignableFrom(returnType) ||
ProtectionDomain.class.isAssignableFrom(returnType)));
private boolean isInvalidReadOnlyPropertyType(@Nullable Class<?> returnType, Class<?> beanClass) {
return (returnType != null && (ClassLoader.class.isAssignableFrom(returnType) ||
ProtectionDomain.class.isAssignableFrom(returnType) ||
(AutoCloseable.class.isAssignableFrom(returnType) &&
!AutoCloseable.class.isAssignableFrom(beanClass))));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ void propertyDescriptors() throws Exception {
assertThat(accessor.isReadableProperty("inputStream")).isFalse();
assertThat(accessor.isReadableProperty("filename")).isTrue();
assertThat(accessor.isReadableProperty("description")).isTrue();

accessor = createAccessor(new ActiveResource());

assertThat(accessor.isReadableProperty("resource")).isTrue();
}

@Test
Expand Down Expand Up @@ -376,6 +380,18 @@ public String getObject() {
}


public static class ActiveResource implements AutoCloseable {

public ActiveResource getResource() {
return this;
}

@Override
public void close() throws Exception {
}
}


public static class GetterWithOptional {

public TestBean value;
Expand Down

0 comments on commit 588a702

Please sign in to comment.