Skip to content

Fix IllegalStateException in owner pets mapping-created-by-agentic #77

@doppleware

Description

@doppleware

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:

  1. Changes the stream collector to use Collectors.groupingBy() with Collectors.mapping()
  2. Properly handles multiple pets per owner by collecting them into lists
  3. Maintains the same output format while fixing the duplicate key issue

Testing Required
The fix should be tested with:

  1. Owners with single pets
  2. Owners with multiple pets
  3. Owners with no pets

Related PR: #76

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions