Class.getDeclaredMethods() is returning inherited methods
david.holmes at oracle.com
Tue Jan 8 01:38:45 UTC 2019
On 7/01/2019 11:35 pm, Michael Rasmussen wrote:
>> On 7/01/2019 8:46 pm, Michael Rasmussen wrote:
>>> We recently discovered something similar, although with the native counterparts of getDeclaredMethods: the JVM-TI function GetClassMethods and the JDI method ReferenceType.methods().
>>> The documentation for which states "Only directly declared methods are returned (not inherited methods)" or "(...) declared directly in this type. Inherited methods are not included."
>>> When running the code pasted below with HotSpot (tried OpenJDK8 and 11), I get the following output:
>>> [public abstract java.lang.String app1.Test$Child.method2()]
>>> [public default java.lang.String app1.Test$Child.method(), public abstract java.lang.String app1.Test$Child.method2()]
>> This would appear to be a bug with JVM TI in how default methods are
>> accounted for. GetClassMethods simply looks at the methods defined in
>> the instanceKlass, but for interfaces default methods are included. I'll
>> look into this in more detail and file a hotspot bug.
> An interesting thing is that it's not the default method "def" that is listed, but the abstract method "method" (with incorrect modifier?)
Sorry yes I misread the original code and just looked at the extra
"default method" in the output. Definitely something not right there.
More information about the core-libs-dev