From c9e0803beedb7284cc6a51a4a67aa20dd1cb6898 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 6 Oct 2017 12:14:48 +0200 Subject: [PATCH] DATACMNS-1191 - Avoid unnecessary investigation of converters in QueryExecutionResultHandler. On query execution conversion, we now check an unwrapped Optional's value for assignability to the target type before looking into advanced conversion options to avoid unnecessary code invocations that would eventually return the same instance anyway. --- .../core/support/QueryExecutionResultHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java b/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java index 023cdc5aa..03dfbb24d 100644 --- a/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java +++ b/src/main/java/org/springframework/data/repository/core/support/QueryExecutionResultHandler.java @@ -66,12 +66,20 @@ class QueryExecutionResultHandler { Class expectedReturnType = returnTypeDescriptor.getType(); + // Early return if the raw value matches + if (result != null && expectedReturnType.isInstance(result)) { return result; } result = unwrapOptional(result); + // Early return if the unrwapped value matches + + if (result != null && expectedReturnType.isInstance(result)) { + return result; + } + if (QueryExecutionConverters.supports(expectedReturnType)) { TypeDescriptor targetType = TypeDescriptor.valueOf(expectedReturnType);