Skip to content

Commit 2a34c0e

Browse files
committed
Return early from composed Converter if initial conversion step returned null
See gh-23379
1 parent fec89af commit 2a34c0e

File tree

1 file changed

+5
-2
lines changed
  • spring-core/src/main/java/org/springframework/core/convert/converter

1 file changed

+5
-2
lines changed

spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ public interface Converter<S, T> {
5757
* @since 5.3
5858
*/
5959
default <U> Converter<S, U> andThen(Converter<? super T, ? extends U> after) {
60-
Assert.notNull(after, "after must not be null");
61-
return (S s) -> after.convert(convert(s));
60+
Assert.notNull(after, "After Converter must not be null");
61+
return (S s) -> {
62+
T initialResult = convert(s);
63+
return (initialResult != null ? after.convert(initialResult) : null);
64+
};
6265
}
6366

6467
}

0 commit comments

Comments
 (0)