Skip to content

Ignore non-component fields when copying records to intermediary - #225

Merged
robert-bor merged 1 commit into
masterfrom
fix/224-record-to-any-unknown-fields
Oct 15, 2026
Merged

robert-bor merged 1 commit into
masterfrom
fix/224-record-to-any-unknown-fields

Conversation

@arjanvlek

Copy link
Copy Markdown
Contributor

Fixes #224

Problem

Mapping a record failed with RecordMappingToIntermediaryException (caused by NoSuchMethodException: <Record>.$$nameOfSyntheticField()) when classes were instrumented with tooling that adds fields to them.

Root cause

RecordToAnyConverter looped over all declared fields of the generated intermediary class and looked up a same-named accessor on the source record. The intermediary is generated in the package of the record, so instrumentation can add a static, synthetic field to it. That field has no accessor on the record, so the lookup failed.

Solution

  • Loop over the record components and read each value with RecordComponent.getAccessor(), instead of looking up methods by field name.
  • Copy a value only when the intermediary has a same-named field that is not static and not synthetic. Ignore all other fields.

Tests

Added to RecordToAnyConverterTest:

  • End-to-end conversion of a record to a class.
  • An intermediary with an extra static field and an extra instance field that the record does not have.
  • An intermediary generated with Javassist that has a public static synthetic field, to simulate an instrumented class.

The two intermediary tests fail without the fix (NoSuchMethodException) and pass with it. The full suite passes (412 tests, 0 failures, 2 skipped).

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.15%. Comparing base (ebcee8e) to head (3dd21f6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #225      +/-   ##
============================================
+ Coverage     85.85%   86.15%   +0.30%     
- Complexity     1175     1180       +5     
============================================
  Files           129      129              
  Lines          2630     2637       +7     
  Branches        307      309       +2     
============================================
+ Hits           2258     2272      +14     
+ Misses          241      234       -7     
  Partials        131      131              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

**Problem/trigger:**
Mapping a record failed with `RecordMappingToIntermediaryException`
(`NoSuchMethodException: <Record>.$$nameOfSyntheticField()`) when a
class runs with instrumentation-added fields (#224).

**Root cause:**
`RecordToAnyConverter` looped over all declared fields of the generated
intermediary class and looked up a same-named accessor on the record.
The intermediary is generated in the package of the record, so a static,
synthetic field was added that has no accessor on the record.

**Solution:**
Loop over the record components and read them with
`RecordComponent.getAccessor()`. Copy a value only when the intermediary
has a same-named field that is not static and not synthetic.

Fixes #224

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@arjanvlek
arjanvlek force-pushed the fix/224-record-to-any-unknown-fields branch from 2d87e30 to 3dd21f6 Compare October 15, 2026 13:38
@sonarqubecloud

Copy link
Copy Markdown

@robert-bor
robert-bor merged commit a4bc9ff into master Oct 15, 2026
6 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.

RecordToAnyConverter throws NoSuchMethodException for target fields that have no accessor on the source record

2 participants