From 2a34c0ea702a1fa0a6dc66a7cedd112aa4c284da Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 12 Oct 2020 17:54:53 +0200 Subject: [PATCH] Return early from composed Converter if initial conversion step returned null See gh-23379 --- .../springframework/core/convert/converter/Converter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java b/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java index e089081c5d0..c1bc0d2131d 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/Converter.java @@ -57,8 +57,11 @@ public interface Converter { * @since 5.3 */ default Converter andThen(Converter after) { - Assert.notNull(after, "after must not be null"); - return (S s) -> after.convert(convert(s)); + Assert.notNull(after, "After Converter must not be null"); + return (S s) -> { + T initialResult = convert(s); + return (initialResult != null ? after.convert(initialResult) : null); + }; } }