Skip to content

Commit e0bfe3f

Browse files
committed
Use Class.getMethod to locate the precise implementation, including default methods in Java 8+ interfaces
1 parent 92e61bb commit e0bfe3f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

mrbean/src/main/java/com/fasterxml/jackson/module/mrbean/BeanBuilder.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,28 @@ protected boolean hasConcreteOverride(Method m0, JavaType implementedType)
181181
{
182182
final String name = m0.getName();
183183
final Class<?>[] argTypes = m0.getParameterTypes();
184+
try {
185+
// getMethod returns the most-specific method implementation, for public methods only (which is any method in an interface)
186+
Method effectiveMethod = implementedType.getRawClass().getMethod(name, argTypes);
187+
if (BeanUtil.isConcrete(effectiveMethod)) {
188+
return true;
189+
}
190+
} catch (NoSuchMethodException e) {
191+
// method must be non-public, fallback to using getDeclaredMethod
192+
}
193+
184194
for (JavaType curr = implementedType; (curr != null) && !curr.isJavaLangObject();
185195
curr = curr.getSuperClass()) {
186196
// 29-Nov-2015, tatu: Avoiding exceptions would be good, so would linear scan
187197
// be better here?
188198
try {
189199
Method effectiveMethod = curr.getRawClass().getDeclaredMethod(name, argTypes);
190-
if (effectiveMethod != null && BeanUtil.isConcrete(effectiveMethod)) {
200+
if (BeanUtil.isConcrete(effectiveMethod)) {
191201
return true;
192202
}
193-
} catch (NoSuchMethodException e) { }
203+
} catch (NoSuchMethodException e) {
204+
// method must exist on a superclass, continue searching...
205+
}
194206
}
195207
return false;
196208
}
@@ -245,7 +257,7 @@ protected final static boolean returnsBoolean(Method m)
245257
Class<?> rt = m.getReturnType();
246258
return (rt == Boolean.class || rt == Boolean.TYPE);
247259
}
248-
260+
249261
/*
250262
/**********************************************************
251263
/* Internal methods, bytecode generation
@@ -354,7 +366,7 @@ protected void createUnimplementedMethod(ClassWriter cw, String internalClassNam
354366
/* Internal methods, other
355367
/**********************************************************
356368
*/
357-
369+
358370
protected String decap(String name) {
359371
char c = name.charAt(0);
360372
if (name.length() > 1

0 commit comments

Comments
 (0)