2222import java .beans .PropertyDescriptor ;
2323import java .lang .reflect .Method ;
2424import java .lang .reflect .Modifier ;
25+ import java .net .URL ;
2526import java .security .ProtectionDomain ;
2627import java .util .Collections ;
2728import java .util .HashSet ;
@@ -292,10 +293,12 @@ private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
292293 // Only allow all name variants of Class properties
293294 continue ;
294295 }
295- if (pd .getWriteMethod () == null && pd .getPropertyType () != null &&
296- (ClassLoader .class .isAssignableFrom (pd .getPropertyType ()) ||
297- ProtectionDomain .class .isAssignableFrom (pd .getPropertyType ()))) {
298- // Ignore ClassLoader and ProtectionDomain read-only properties - no need to bind to those
296+ if (URL .class == beanClass && "content" .equals (pd .getName ())) {
297+ // Only allow URL attribute introspection, not content resolution
298+ continue ;
299+ }
300+ if (pd .getWriteMethod () == null && isInvalidReadOnlyPropertyType (pd .getPropertyType ())) {
301+ // Ignore read-only properties such as ClassLoader - no need to bind to those
299302 continue ;
300303 }
301304 if (logger .isTraceEnabled ()) {
@@ -344,10 +347,8 @@ private void introspectInterfaces(Class<?> beanClass, Class<?> currClass, Set<St
344347 // GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
345348 // against a declared read method, so we prefer read method descriptors here.
346349 pd = buildGenericTypeAwarePropertyDescriptor (beanClass , pd );
347- if (pd .getWriteMethod () == null && pd .getPropertyType () != null &&
348- (ClassLoader .class .isAssignableFrom (pd .getPropertyType ()) ||
349- ProtectionDomain .class .isAssignableFrom (pd .getPropertyType ()))) {
350- // Ignore ClassLoader and ProtectionDomain read-only properties - no need to bind to those
350+ if (pd .getWriteMethod () == null && isInvalidReadOnlyPropertyType (pd .getPropertyType ())) {
351+ // Ignore read-only properties such as ClassLoader - no need to bind to those
351352 continue ;
352353 }
353354 this .propertyDescriptors .put (pd .getName (), pd );
@@ -379,8 +380,7 @@ private boolean isPlainAccessor(Method method) {
379380 if (Modifier .isStatic (method .getModifiers ()) ||
380381 method .getDeclaringClass () == Object .class || method .getDeclaringClass () == Class .class ||
381382 method .getParameterCount () > 0 || method .getReturnType () == void .class ||
382- ClassLoader .class .isAssignableFrom (method .getReturnType ()) ||
383- ProtectionDomain .class .isAssignableFrom (method .getReturnType ())) {
383+ isInvalidReadOnlyPropertyType (method .getReturnType ())) {
384384 return false ;
385385 }
386386 try {
@@ -393,6 +393,12 @@ private boolean isPlainAccessor(Method method) {
393393 }
394394 }
395395
396+ private boolean isInvalidReadOnlyPropertyType (@ Nullable Class <?> returnType ) {
397+ return (returnType != null && (AutoCloseable .class .isAssignableFrom (returnType ) ||
398+ ClassLoader .class .isAssignableFrom (returnType ) ||
399+ ProtectionDomain .class .isAssignableFrom (returnType )));
400+ }
401+
396402
397403 BeanInfo getBeanInfo () {
398404 return this .beanInfo ;
0 commit comments