[Bug]: CtRecord.setTypeMembers adds method due to wrong polarity check
Describe the bug
When using CtRecord.setTypeMembers, with an existing accessor method for a component, the implicit accessor is still created. This is the code snippet from CtRecordImpl in trunk:
@Override
public <C extends CtType<Object>> C setTypeMembers(List<CtTypeMember> members) {
super.setTypeMembers(members);
for (CtRecordComponent component : components) {
**if (hasMethodWithSameNameAndNoParameter(component)) {**
addMethod(component.toMethod());
}
if (getField(component.getSimpleName()) == null) {
addField(component.toField());
}
}
return (C) this;
}
The marked line should read:
if (!hasMethodWithSameNameAndNoParameter(component)) {
Other places in the file using this logic look fine.
Happy to open a PR if needed.
Source code you are trying to analyze/transform
Source code for your Spoon processing
Actual output
Expected output
Spoon Version
11.5.0
JVM Version
openjdk version "21.0.13" 2026-10-20 LTS
What operating system are you using?
MacOS X
Hi @kevemueller, I have submitted PR #6987 to address this issue.
The fix corrects the inverted condition in CtRecordImpl#setTypeMembers() so that an implicit accessor is only generated when an explicit accessor does not already exist.
I've also added a regression test to verify that explicit record accessors are preserved.
The targeted test and the complete CtRecordTest suite pass successfully.