Browse Source

Defensively handle loadClass null result in BeanUtils.findEditorByConvention

Closes gh-26252
pull/26260/head
Juergen Hoeller 5 years ago
parent
commit
2a47751fcd
  1. 9
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

9
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

@ -543,6 +543,7 @@ public abstract class BeanUtils { @@ -543,6 +543,7 @@ public abstract class BeanUtils {
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
return null;
}
ClassLoader cl = targetType.getClassLoader();
if (cl == null) {
try {
@ -559,10 +560,12 @@ public abstract class BeanUtils { @@ -559,10 +560,12 @@ public abstract class BeanUtils {
return null;
}
}
String targetTypeName = targetType.getName();
String editorName = targetTypeName + "Editor";
try {
Class<?> editorClass = cl.loadClass(editorName);
if (editorClass != null) {
if (!PropertyEditor.class.isAssignableFrom(editorClass)) {
if (logger.isInfoEnabled()) {
logger.info("Editor class [" + editorName +
@ -573,7 +576,12 @@ public abstract class BeanUtils { @@ -573,7 +576,12 @@ public abstract class BeanUtils {
}
return (PropertyEditor) instantiateClass(editorClass);
}
// Misbehaving ClassLoader returned null instead of ClassNotFoundException
// - fall back to unknown editor type registration below
}
catch (ClassNotFoundException ex) {
// Ignore - fall back to unknown editor type registration below
}
if (logger.isTraceEnabled()) {
logger.trace("No property editor [" + editorName + "] found for type " +
targetTypeName + " according to 'Editor' suffix convention");
@ -581,7 +589,6 @@ public abstract class BeanUtils { @@ -581,7 +589,6 @@ public abstract class BeanUtils {
unknownEditorTypes.add(targetType);
return null;
}
}
/**
* Determine the bean property type for the given property from the

Loading…
Cancel
Save