forked from digma-ai/forkof-spring-petclinic
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
Issue Description
When retrieving pets for an owner through the /owners/{ownerId}/pets endpoint, an IllegalStateException occurs if the owner has multiple pets due to a duplicate key error in the stream collection process.
Error Details
java.lang.IllegalStateException: Duplicate key 3 (attempted merging values [3] and [4])
Root Cause
The current implementation uses Collectors.toMap() which doesn't handle duplicate keys properly when mapping pets to owners. This fails when an owner has multiple pets since it tries to create a one-to-one mapping instead of a one-to-many mapping.
Solution
A fix has been implemented in PR #76 that:
- Changes the stream collector to use
Collectors.groupingBy()withCollectors.mapping() - Properly handles multiple pets per owner by collecting them into lists
- Maintains the same output format while fixing the duplicate key issue
Testing Required
The fix should be tested with:
- Owners with single pets
- Owners with multiple pets
- Owners with no pets
Related PR: #76
Reactions are currently unavailable