Skip to content

Use the canonical constructor when mapping Java record inputs - #2361

Merged
jjacobs44 merged 1 commit into
Netflix:masterfrom
auraseb:fix/record-secondary-constructor
Oct 19, 2026
Merged

jjacobs44 merged 1 commit into
Netflix:masterfrom
auraseb:fix/record-secondary-constructor

Conversation

@auraseb

@auraseb auraseb commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Pull request checklist

  • Please read our contributor guide
  • Consider creating a discussion on the discussion forum
    first
  • Make sure the PR doesn't introduce backward compatibility issues
  • Make sure to have sufficient test cases

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Changes in this PR

DefaultInputObjectMapper.handleRecordClass used declaredConstructors.first() to build a record. The order of getDeclaredConstructors() is unspecified, and when a record declares a convenience constructor HotSpot returns that one first, so mapping failed with IllegalArgumentException: wrong number of arguments.

The mapper now looks up the canonical constructor by the record component types, which is how the canonical constructor is defined by the JLS.

Tests added in InputObjectMapperTest:

  • a plain record (RecordInput, which existed as a fixture but was not used by any test)
  • a record with an additional constructor (RecordInputWithSecondaryConstructor), which fails on master and passes with this change

Issue #

Alternatives considered

Filtering declaredConstructors by parameter count. That still picks the wrong constructor when a second constructor has the same arity, so looking it up by component types is the precise option.

Fixes #2360

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
@jjacobs44
jjacobs44 merged commit 86712c4 into Netflix:master Oct 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java record input fails to map when the record declares an additional constructor

2 participants