Skip to content

Commit cfdceae

Browse files
committed
Defensively handle loadClass null result in BeanUtils.findEditorByConvention
Closes spring-projectsgh-26252 (cherry picked from commit 2a47751)
1 parent 1764780 commit cfdceae

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetTyp
506506
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
507507
return null;
508508
}
509+
509510
ClassLoader cl = targetType.getClassLoader();
510511
if (cl == null) {
511512
try {
@@ -522,28 +523,34 @@ public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetTyp
522523
return null;
523524
}
524525
}
526+
525527
String targetTypeName = targetType.getName();
526528
String editorName = targetTypeName + "Editor";
527529
try {
528530
Class<?> editorClass = cl.loadClass(editorName);
529-
if (!PropertyEditor.class.isAssignableFrom(editorClass)) {
530-
if (logger.isInfoEnabled()) {
531-
logger.info("Editor class [" + editorName +
532-
"] does not implement [java.beans.PropertyEditor] interface");
531+
if (editorClass != null) {
532+
if (!PropertyEditor.class.isAssignableFrom(editorClass)) {
533+
if (logger.isInfoEnabled()) {
534+
logger.info("Editor class [" + editorName +
535+
"] does not implement [java.beans.PropertyEditor] interface");
536+
}
537+
unknownEditorTypes.add(targetType);
538+
return null;
533539
}
534-
unknownEditorTypes.add(targetType);
535-
return null;
540+
return (PropertyEditor) instantiateClass(editorClass);
536541
}
537-
return (PropertyEditor) instantiateClass(editorClass);
542+
// Misbehaving ClassLoader returned null instead of ClassNotFoundException
543+
// - fall back to unknown editor type registration below
538544
}
539545
catch (ClassNotFoundException ex) {
540-
if (logger.isTraceEnabled()) {
541-
logger.trace("No property editor [" + editorName + "] found for type " +
542-
targetTypeName + " according to 'Editor' suffix convention");
543-
}
544-
unknownEditorTypes.add(targetType);
545-
return null;
546+
// Ignore - fall back to unknown editor type registration below
546547
}
548+
if (logger.isTraceEnabled()) {
549+
logger.trace("No property editor [" + editorName + "] found for type " +
550+
targetTypeName + " according to 'Editor' suffix convention");
551+
}
552+
unknownEditorTypes.add(targetType);
553+
return null;
547554
}
548555

549556
/**

0 commit comments

Comments
 (0)