Skip to content

Commit

Permalink
Merge pull request #17279 from yrodiere/duplicate-getters
Browse files Browse the repository at this point in the history
Handle Class.getMethods() returning multiple getters with just the return type differring
  • Loading branch information
Sanne authored May 17, 2021
2 parents 168eb0c + 88e771e commit fa0d945
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public Property[] apply(Class<?> type) {
if (i.getName().startsWith("get") && i.getName().length() > 3 && i.getParameterCount() == 0
&& i.getReturnType() != void.class) {
String name = Character.toLowerCase(i.getName().charAt(3)) + i.getName().substring(4);
getters.put(name, i);
Method existingGetter = getters.get(name);
// In some cases the overridden methods from supertypes can also appear in the array (for some reason).
// We want the most specific methods.
if (existingGetter == null || existingGetter.getReturnType().isAssignableFrom(i.getReturnType())) {
getters.put(name, i);
}
} else if (i.getName().startsWith("is") && i.getName().length() > 3 && i.getParameterCount() == 0
&& i.getReturnType() == boolean.class) {
String name = Character.toLowerCase(i.getName().charAt(2)) + i.getName().substring(3);
Expand Down

0 comments on commit fa0d945

Please sign in to comment.