Merge remote-tracking branch 'origin/handling_null_pointer_exception_ownerID' into handling_null_pointer_exception_ownerID

# Conflicts:
#	src/main/java/org/springframework/samples/petclinic/owner/PetController.java
This commit is contained in:
bijomutta 2023-07-14 11:08:13 +02:00
commit c6b90506af

View file

@ -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")