DATAREST-353 - Fixed potential NullPointerException when trying to delete a non-existing resource.

We now correctly return a 404 Not Found in case we receive a DELETE request for a resource not existing.
This commit is contained in:
Oliver Gierke
2014-07-16 17:44:02 +02:00
parent 07a8dd2ca6
commit aa28aebca5
2 changed files with 16 additions and 0 deletions

View File

@@ -360,6 +360,10 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
RepositoryInvoker invoker = resourceInformation.getInvoker();
Object domainObj = invoker.invokeFindOne(id);
if (domainObj == null) {
throw new ResourceNotFoundException();
}
publisher.publishEvent(new BeforeDeleteEvent(domainObj));
invoker.invokeDelete(id);
publisher.publishEvent(new AfterDeleteEvent(domainObj));

View File

@@ -545,6 +545,18 @@ public class JpaWebTests extends AbstractWebIntegrationTests {
follow(new Link(href)).andExpect(hasLinkWithRel("books"));
}
/**
* @see DATAREST-353
*/
@Test
public void returns404WhenTryingToDeleteANonExistingResource() throws Exception {
Link authorsLink = discoverUnique("authors");
mvc.perform(delete(authorsLink.getHref().concat("/{id}"), 4711)).//
andExpect(status().isNotFound());
}
/**
* Asserts the {@link Person} resource the given link points to contains siblings with the given names.
*