Skip to content

Commit 2a47751

Browse files
committed
Defensively handle loadClass null result in BeanUtils.findEditorByConvention
Closes gh-26252
1 parent 06e3528 commit 2a47751

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
@@ -543,6 +543,7 @@ public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetTyp
543543
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
544544
return null;
545545
}
546+
546547
ClassLoader cl = targetType.getClassLoader();
547548
if (cl == null) {
548549
try {
@@ -559,28 +560,34 @@ public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetTyp
559560
return null;
560561
}
561562
}
563+
562564
String targetTypeName = targetType.getName();
563565
String editorName = targetTypeName + "Editor";
564566
try {
565567
Class<?> editorClass = cl.loadClass(editorName);
566-
if (!PropertyEditor.class.isAssignableFrom(editorClass)) {
567-
if (logger.isInfoEnabled()) {
568-
logger.info("Editor class [" + editorName +
569-
"] does not implement [java.beans.PropertyEditor] interface");
568+
if (editorClass != null) {
569+
if (!PropertyEditor.class.isAssignableFrom(editorClass)) {
570+
if (logger.isInfoEnabled()) {
571+
logger.info("Editor class [" + editorName +
572+
"] does not implement [java.beans.PropertyEditor] interface");
573+
}
574+
unknownEditorTypes.add(targetType);
575+
return null;
570576
}
571-
unknownEditorTypes.add(targetType);
572-
return null;
577+
return (PropertyEditor) instantiateClass(editorClass);
573578
}
574-
return (PropertyEditor) instantiateClass(editorClass);
579+
// Misbehaving ClassLoader returned null instead of ClassNotFoundException
580+
// - fall back to unknown editor type registration below
575581
}
576582
catch (ClassNotFoundException ex) {
577-
if (logger.isTraceEnabled()) {
578-
logger.trace("No property editor [" + editorName + "] found for type " +
579-
targetTypeName + " according to 'Editor' suffix convention");
580-
}
581-
unknownEditorTypes.add(targetType);
582-
return null;
583+
// Ignore - fall back to unknown editor type registration below
583584
}
585+
if (logger.isTraceEnabled()) {
586+
logger.trace("No property editor [" + editorName + "] found for type " +
587+
targetTypeName + " according to 'Editor' suffix convention");
588+
}
589+
unknownEditorTypes.add(targetType);
590+
return null;
584591
}
585592

586593
/**

0 commit comments

Comments
 (0)