22
22
import java .beans .PropertyDescriptor ;
23
23
import java .lang .reflect .Method ;
24
24
import java .lang .reflect .Modifier ;
25
+ import java .net .URL ;
25
26
import java .security .ProtectionDomain ;
26
27
import java .util .Collections ;
27
28
import java .util .HashSet ;
@@ -292,10 +293,12 @@ private CachedIntrospectionResults(Class<?> beanClass) throws BeansException {
292
293
// Only allow all name variants of Class properties
293
294
continue ;
294
295
}
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
299
302
continue ;
300
303
}
301
304
if (logger .isTraceEnabled ()) {
@@ -344,10 +347,8 @@ private void introspectInterfaces(Class<?> beanClass, Class<?> currClass, Set<St
344
347
// GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
345
348
// against a declared read method, so we prefer read method descriptors here.
346
349
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
351
352
continue ;
352
353
}
353
354
this .propertyDescriptors .put (pd .getName (), pd );
@@ -379,8 +380,7 @@ private boolean isPlainAccessor(Method method) {
379
380
if (Modifier .isStatic (method .getModifiers ()) ||
380
381
method .getDeclaringClass () == Object .class || method .getDeclaringClass () == Class .class ||
381
382
method .getParameterCount () > 0 || method .getReturnType () == void .class ||
382
- ClassLoader .class .isAssignableFrom (method .getReturnType ()) ||
383
- ProtectionDomain .class .isAssignableFrom (method .getReturnType ())) {
383
+ isInvalidReadOnlyPropertyType (method .getReturnType ())) {
384
384
return false ;
385
385
}
386
386
try {
@@ -393,6 +393,12 @@ private boolean isPlainAccessor(Method method) {
393
393
}
394
394
}
395
395
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
+
396
402
397
403
BeanInfo getBeanInfo () {
398
404
return this .beanInfo ;
0 commit comments