Skip to content

Commit c57bfec

Browse files
committed
DATACMNS-828 - Fixed potential NullPointerException in ResultProcessor.
ResultProcessor.processResult(…) now explicitly handles null values to prevent IllegalArgumentExceptions being provoked in the ProjectionFactory which occurred if null values were handed down to it.
1 parent 9dc23ed commit c57bfec

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/main/java/org/springframework/data/repository/query/ResultProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -121,7 +121,7 @@ public <T> T processResult(Object source) {
121121
@SuppressWarnings("unchecked")
122122
public <T> T processResult(Object source, Converter<Object, Object> preparingConverter) {
123123

124-
if (type.isInstance(source) || !type.isProjecting()) {
124+
if (source == null || type.isInstance(source) || !type.isProjecting()) {
125125
return (T) source;
126126
}
127127

src/test/java/org/springframework/data/repository/query/ResultProcessorUnitTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -186,6 +186,14 @@ public Object convert(Object source) {
186186
assertThat(result, is(instanceOf(SampleDTO.class)));
187187
}
188188

189+
/**
190+
* @see DATACMNS-828
191+
*/
192+
@Test
193+
public void returnsNullResultAsIs() throws Exception {
194+
assertThat(getProcessor("findOneDto").processResult(null), is(nullValue()));
195+
}
196+
189197
private static ResultProcessor getProcessor(String methodName, Class<?>... parameters) throws Exception {
190198
return getQueryMethod(methodName, parameters).getResultProcessor();
191199
}

0 commit comments

Comments
 (0)