diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java index 0c0058f3a..c3334bab8 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -56,23 +56,13 @@ class PetController { @ModelAttribute("owner") public Owner findOwner(@PathVariable("ownerId") int ownerId) { - - Owner owner = this.owners.findById(ownerId); - if (owner == null) { - throw new IllegalArgumentException("Owner ID not found: " + ownerId); - } - return owner; + return this.owners.findById(ownerId); } @ModelAttribute("pet") public Pet findPet(@PathVariable("ownerId") int ownerId, @PathVariable(name = "petId", required = false) Integer petId) { - - Owner owner = this.owners.findById(ownerId); - if (owner == null) { - throw new IllegalArgumentException("Owner ID not found: " + ownerId); - } - return petId == null ? new Pet() : owner.getPet(petId); + return petId == null ? new Pet() : this.owners.findById(ownerId).getPet(petId); } @InitBinder("owner")