You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fixes duplicate field name handling in InstanceCoercer#getFieldWriters.
Previously, field writers were collected using Collectors.toMap(...) without an explicit merge strategy. When duplicate field names were encountered (for example through field hiding in inheritance), the collector would fail with an implicit IllegalStateException caused by duplicate keys.
This change makes duplicate handling explicit by detecting duplicates during map collection and throwing a JsonException with a clear error message.
This prevents ambiguous field mappings and replaces the implicit collector failure with a controlled and descriptive exception.
🔧 Implementation Notes
The change modifies the Collectors.toMap(...) call in getFieldWriters.
Previous behavior
Collectors.toMap was used without a merge function.
Duplicate field names caused an implicit IllegalStateException from the collector.
New behavior
A merge function is provided that throws a JsonException when duplicate field names are encountered.
This makes the failure explicit and easier to diagnose.
Example scenario that previously caused an implicit collector failure:
Fix duplicate field name handling in InstanceCoercer#getFieldWriters
🐞 Bug fix
Walkthroughs
Description
• Fixes duplicate field name handling in InstanceCoercer#getFieldWriters
• Adds merge function to Collectors.toMap() to retain first entry
• Uses LinkedHashMap to preserve field processing order
• Prevents runtime IllegalStateException on duplicate keys
Add merge function and LinkedHashMap to toMap collector
• Modified Collectors.toMap() call to include merge function (existing, ignored) -> existing
• Added LinkedHashMap::new as map supplier to preserve insertion order
• Prevents IllegalStateException: Duplicate key when multiple fields resolve to same serialized
name
• Retains first discovered field writer and ignores subsequent duplicates
The change alters runtime behavior for duplicate field names (now silently keeping the first writer)
without adding a unit test to prevent regressions. This makes it easy for future refactors to
reintroduce duplicate-key failures or change which field “wins” without detection.
PR Compliance ID 4 requires adding/updating tests for behavior changes where feasible. The updated
collector explicitly changes behavior on duplicate keys, and the PR itself notes tests as follow-up
work rather than including them.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`InstanceCoercer#getFieldWriters` now retains the first writer when duplicate field names occur, but this behavior change is not covered by tests.
## Issue Context
Duplicate field names can happen via field hiding (same-named fields across a class hierarchy). Historically this could throw `Duplicate key` during collection; now duplicates are ignored. This should be locked in with a unit test to prevent regressions and to ensure deterministic "winner" behavior.
## Fix Focus Areas
- java/src/org/openqa/selenium/json/InstanceCoercer.java[99-132]
- java/test/org/openqa/selenium/json/JsonTest.java[113-145]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
getFieldWriters now silently ignores later fields that resolve to the same JSON key, which can
hide ambiguous class designs (field hiding) and lead to missing/incorrectly-applied data without any
signal. This trades a clear failure (duplicate key exception) for silent data loss and harder
debugging when duplicates exist.
Fields are collected starting from the concrete class and then walking up the superclass chain, and
the collector now keeps the first entry and drops subsequent ones for the same key. During
deserialization only the retained writer is used for a given JSON key, so any dropped duplicate
field can never be set, with no warning/error emitted by this code path.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`InstanceCoercer#getFieldWriters` now resolves duplicate field-name collisions by silently keeping the first writer and ignoring the rest. This can cause silent data loss / surprising field selection when a subclass hides a superclass field, making deserialization bugs very hard to detect.
### Issue Context
The stream collects fields across the class hierarchy and then builds a map keyed by `Field::getName`. With the new merge function, duplicates are no longer surfaced to the caller.
### Fix Focus Areas
- java/src/org/openqa/selenium/json/InstanceCoercer.java[99-132]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
ⓘ The new review experience is currently in Beta. Learn more
seethinajayadileep
changed the title
Fix duplicate field name handling in InstanceCoercer#getFieldWriters
[java] Fix duplicate field name handling in InstanceCoercer#getFieldWriters
Mar 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💥 What does this PR do?
This PR fixes duplicate field name handling in
InstanceCoercer#getFieldWriters.Previously, field writers were collected using
Collectors.toMap(...)without an explicit merge strategy. When duplicate field names were encountered (for example through field hiding in inheritance), the collector would fail with an implicitIllegalStateExceptioncaused by duplicate keys.This change makes duplicate handling explicit by detecting duplicates during map collection and throwing a
JsonExceptionwith a clear error message.This prevents ambiguous field mappings and replaces the implicit collector failure with a controlled and descriptive exception.
🔧 Implementation Notes
The change modifies the
Collectors.toMap(...)call ingetFieldWriters.Previous behavior
Collectors.toMapwas used without a merge function.IllegalStateExceptionfrom the collector.New behavior
JsonExceptionwhen duplicate field names are encountered.Example scenario that previously caused an implicit collector failure: