diff --git a/src/main/java/org/springframework/data/repository/query/ResultProcessor.java b/src/main/java/org/springframework/data/repository/query/ResultProcessor.java index 073f0d43a..76e24fa87 100644 --- a/src/main/java/org/springframework/data/repository/query/ResultProcessor.java +++ b/src/main/java/org/springframework/data/repository/query/ResultProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -121,7 +121,7 @@ public class ResultProcessor { @SuppressWarnings("unchecked") public T processResult(Object source, Converter preparingConverter) { - if (type.isInstance(source) || !type.isProjecting()) { + if (source == null || type.isInstance(source) || !type.isProjecting()) { return (T) source; } diff --git a/src/test/java/org/springframework/data/repository/query/ResultProcessorUnitTests.java b/src/test/java/org/springframework/data/repository/query/ResultProcessorUnitTests.java index 265d29f86..4219fb63d 100644 --- a/src/test/java/org/springframework/data/repository/query/ResultProcessorUnitTests.java +++ b/src/test/java/org/springframework/data/repository/query/ResultProcessorUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -186,6 +186,14 @@ public class ResultProcessorUnitTests { assertThat(result, is(instanceOf(SampleDTO.class))); } + /** + * @see DATACMNS-828 + */ + @Test + public void returnsNullResultAsIs() throws Exception { + assertThat(getProcessor("findOneDto").processResult(null), is(nullValue())); + } + private static ResultProcessor getProcessor(String methodName, Class... parameters) throws Exception { return getQueryMethod(methodName, parameters).getResultProcessor(); }