From cdd925d664e678f6d1a2f768ff02e374a5e55fef Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 11 Jan 2024 13:18:33 +0000 Subject: [PATCH] Small optimization for empty petId --- .../samples/petclinic/owner/PetController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 fae63b8fb..057456643 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -68,11 +68,15 @@ class PetController { public Pet findPet(@PathVariable("ownerId") int ownerId, @PathVariable(name = "petId", required = false) Integer petId) { + if (petId == null) { + return new Pet(); + } + 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 owner.getPet(petId); } @InitBinder("owner")