@@ -295,7 +295,7 @@ private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
295295 // Only allow URL attribute introspection, not content resolution
296296 continue ;
297297 }
298- if (pd .getWriteMethod () == null && isInvalidReadOnlyPropertyType (pd .getPropertyType ())) {
298+ if (pd .getWriteMethod () == null && isInvalidReadOnlyPropertyType (pd .getPropertyType (), beanClass )) {
299299 // Ignore read-only properties such as ClassLoader - no need to bind to those
300300 continue ;
301301 }
@@ -345,7 +345,8 @@ private void introspectInterfaces(Class<?> beanClass, Class<?> currClass, Set<St
345345 // GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
346346 // against a declared read method, so we prefer read method descriptors here.
347347 pd = buildGenericTypeAwarePropertyDescriptor (beanClass , pd );
348- if (pd .getWriteMethod () == null && isInvalidReadOnlyPropertyType (pd .getPropertyType ())) {
348+ if (pd .getWriteMethod () == null &&
349+ isInvalidReadOnlyPropertyType (pd .getPropertyType (), beanClass )) {
349350 // Ignore read-only properties such as ClassLoader - no need to bind to those
350351 continue ;
351352 }
@@ -378,7 +379,7 @@ private boolean isPlainAccessor(Method method) {
378379 if (Modifier .isStatic (method .getModifiers ()) ||
379380 method .getDeclaringClass () == Object .class || method .getDeclaringClass () == Class .class ||
380381 method .getParameterCount () > 0 || method .getReturnType () == void .class ||
381- isInvalidReadOnlyPropertyType (method .getReturnType ())) {
382+ isInvalidReadOnlyPropertyType (method .getReturnType (), method . getDeclaringClass () )) {
382383 return false ;
383384 }
384385 try {
@@ -391,10 +392,11 @@ private boolean isPlainAccessor(Method method) {
391392 }
392393 }
393394
394- private boolean isInvalidReadOnlyPropertyType (@ Nullable Class <?> returnType ) {
395- return (returnType != null && (AutoCloseable .class .isAssignableFrom (returnType ) ||
396- ClassLoader .class .isAssignableFrom (returnType ) ||
397- ProtectionDomain .class .isAssignableFrom (returnType )));
395+ private boolean isInvalidReadOnlyPropertyType (@ Nullable Class <?> returnType , Class <?> beanClass ) {
396+ return (returnType != null && (ClassLoader .class .isAssignableFrom (returnType ) ||
397+ ProtectionDomain .class .isAssignableFrom (returnType ) ||
398+ (AutoCloseable .class .isAssignableFrom (returnType ) &&
399+ !AutoCloseable .class .isAssignableFrom (beanClass ))));
398400 }
399401
400402
0 commit comments