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 1674be28fb
commit cb5f04083f
2 changed files with 16 additions and 0 deletions

View File

@@ -326,6 +326,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

@@ -524,6 +524,18 @@ public class JpaWebTests extends AbstractWebIntegrationTests {
assertThat(JsonPath.<JSONArray> read(responseBody, "$.content"), hasSize(0));
}
/**
* @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.
*