DATAREST-331 - Fixed NullPointerException in ResourcesProcessorWrapper.

During type matching in ResourcesProcessorWrapper we now accomodate the scenario that a Resources type is completely different than the Resources type to look for. This resulted in null being returned for the supertype generics lookup and this failed as the corresponding guard was missing.
This commit is contained in:
Oliver Gierke
2014-06-26 11:24:55 +02:00
parent 2401f98d93
commit 6d6f32a9b3
2 changed files with 21 additions and 1 deletions

View File

@@ -439,7 +439,13 @@ public class ResourceProcessorHandlerMethodReturnValueHandler implements Handler
Class<?> resourcesType = resources.getClass();
TypeInformation<?> resourceTypeInformation = target.getSuperTypeInformation(resourcesType).getComponentType();
TypeInformation<?> superTypeInformation = target.getSuperTypeInformation(resourcesType);
if (superTypeInformation == null) {
return false;
}
TypeInformation<?> resourceTypeInformation = superTypeInformation.getComponentType();
return ResourceProcessorWrapper.isValueTypeMatch((Resource<?>) element, resourceTypeInformation);
}
}

View File

@@ -241,6 +241,20 @@ public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests {
assertThat(projectionProcessor.invoked, is(true));
}
/**
* @see DATAREST-331
*/
@Test
public void doesNotMatchOnNonMatchingResourcesTypes() throws Exception {
Resource<Object> resource = new Resource<Object>(new Object());
PagedResources<Resource<Object>> pagedResources = new PagedResources<Resource<Object>>(
Collections.singleton(resource), new PageMetadata(1, 0, 10));
TypeInformation<?> type = ClassTypeInformation.from(RepositoryLinksResource.class);
assertThat(ResourcesProcessorWrapper.isValueTypeMatch(pagedResources, type), is(false));
}
// Helpers ---------------------------------------------------------//
private void invokeReturnValueHandler(String method, final Matcher<?> matcher, Object returnValue) throws Exception {
final MethodParameter methodParam = METHOD_PARAMS.get(method);