Browse Source

Defensively handle loadClass null result in BeanUtils.findEditorByConvention

Closes gh-26252

(cherry picked from commit 2a47751fcd)
pull/26273/head
Juergen Hoeller 5 years ago
parent
commit
cfdceae70f
  1. 9
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

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

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

Loading…
Cancel
Save