Skip to content

Fix FieldUtils.getField false ambiguity on inherited interface field#1748

Merged
garydgregory merged 1 commit into
apache:masterfrom
alhudz:fieldutils-getfield-inherited-ambiguity
Jul 13, 2026
Merged

Fix FieldUtils.getField false ambiguity on inherited interface field#1748
garydgregory merged 1 commit into
apache:masterfrom
alhudz:fieldutils-getfield-inherited-ambiguity

Conversation

@alhudz

@alhudz alhudz commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Repro: FieldUtils.getField(cls, "CONSTANT") where cls implements an interface that extends the interface actually declaring CONSTANT (or a diamond where two implemented interfaces share a common super-interface).
Cause: ClassUtils.getAllInterfaces also returns the transitively inherited interfaces, so class1.getField(fieldName) resolves the same Field more than once; the loop rejects on match == null alone and raises a false IllegalArgumentException about the field being ambiguous across two or more interfaces.
Fix: only reject when the newly found field differs (match == null || match.equals(test)). Field.equals compares declaring class, name and type, so the identical inherited field dedupes while two different fields on unrelated interfaces still throw.

@garydgregory garydgregory changed the title fix FieldUtils.getField false ambiguity on inherited interface field Fix FieldUtils.getField false ambiguity on inherited interface field Jul 13, 2026
@garydgregory garydgregory merged commit 0c40939 into apache:master Jul 13, 2026
20 of 21 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.

2 participants