Skip to content

Fix IllegalStateException in owner pets endpoint-created-by-agentic #358

@shaykeren

Description

@shaykeren

An IllegalStateException is occurring in the GET /owners/{ownerId}/pets endpoint due to improper handling of multiple pets per owner in the stream collection operation.

Problem:
The current implementation fails when attempting to merge pet lists for owners with multiple pets (specifically observed with owner ID 6 having pets 7 and 8).

Root Cause:
The stream collection operation using toMap does not properly handle the case where an owner has multiple pets, leading to duplicate key exceptions.

Solution:
A PR has been created (#357) that implements the following fixes:

  1. Replaces toMap collector with groupingBy to properly handle multiple pets per owner
  2. Uses ArrayList for mutable list structures
  3. Adds proper null handling
  4. Fixes the stream collection logic for multiple pets

Testing:
The fix has been tested with:

  • Owner ID 6 (having pets 7 and 8)
  • Owners with single pets
  • Owners with no pets

Please review and merge PR #357 to resolve this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions