Skip to content

Commit 588a702

Browse files
committed
Merge branch '5.3.x'
# Conflicts: # spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
2 parents 28cd39a + ec3f59e commit 588a702

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
270270
// Only allow URL attribute introspection, not content resolution
271271
continue;
272272
}
273-
if (pd.getWriteMethod() == null && isInvalidReadOnlyPropertyType(pd.getPropertyType())) {
273+
if (pd.getWriteMethod() == null && isInvalidReadOnlyPropertyType(pd.getPropertyType(), beanClass)) {
274274
// Ignore read-only properties such as ClassLoader - no need to bind to those
275275
continue;
276276
}
@@ -320,7 +320,8 @@ private void introspectInterfaces(Class<?> beanClass, Class<?> currClass, Set<St
320320
// GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
321321
// against a declared read method, so we prefer read method descriptors here.
322322
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
323-
if (pd.getWriteMethod() == null && isInvalidReadOnlyPropertyType(pd.getPropertyType())) {
323+
if (pd.getWriteMethod() == null &&
324+
isInvalidReadOnlyPropertyType(pd.getPropertyType(), beanClass)) {
324325
// Ignore read-only properties such as ClassLoader - no need to bind to those
325326
continue;
326327
}
@@ -353,7 +354,7 @@ private boolean isPlainAccessor(Method method) {
353354
if (Modifier.isStatic(method.getModifiers()) ||
354355
method.getDeclaringClass() == Object.class || method.getDeclaringClass() == Class.class ||
355356
method.getParameterCount() > 0 || method.getReturnType() == void.class ||
356-
isInvalidReadOnlyPropertyType(method.getReturnType())) {
357+
isInvalidReadOnlyPropertyType(method.getReturnType(), method.getDeclaringClass())) {
357358
return false;
358359
}
359360
try {
@@ -366,10 +367,11 @@ private boolean isPlainAccessor(Method method) {
366367
}
367368
}
368369

369-
private boolean isInvalidReadOnlyPropertyType(@Nullable Class<?> returnType) {
370-
return (returnType != null && (AutoCloseable.class.isAssignableFrom(returnType) ||
371-
ClassLoader.class.isAssignableFrom(returnType) ||
372-
ProtectionDomain.class.isAssignableFrom(returnType)));
370+
private boolean isInvalidReadOnlyPropertyType(@Nullable Class<?> returnType, Class<?> beanClass) {
371+
return (returnType != null && (ClassLoader.class.isAssignableFrom(returnType) ||
372+
ProtectionDomain.class.isAssignableFrom(returnType) ||
373+
(AutoCloseable.class.isAssignableFrom(returnType) &&
374+
!AutoCloseable.class.isAssignableFrom(beanClass))));
373375
}
374376

375377

spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ void propertyDescriptors() throws Exception {
216216
assertThat(accessor.isReadableProperty("inputStream")).isFalse();
217217
assertThat(accessor.isReadableProperty("filename")).isTrue();
218218
assertThat(accessor.isReadableProperty("description")).isTrue();
219+
220+
accessor = createAccessor(new ActiveResource());
221+
222+
assertThat(accessor.isReadableProperty("resource")).isTrue();
219223
}
220224

221225
@Test
@@ -376,6 +380,18 @@ public String getObject() {
376380
}
377381

378382

383+
public static class ActiveResource implements AutoCloseable {
384+
385+
public ActiveResource getResource() {
386+
return this;
387+
}
388+
389+
@Override
390+
public void close() throws Exception {
391+
}
392+
}
393+
394+
379395
public static class GetterWithOptional {
380396

381397
public TestBean value;

0 commit comments

Comments
 (0)