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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user