RFR: 8347826: Introspector shows wrong method list after 8071693 [v4]
Roman Marchenko
rmarchenko at openjdk.org
Wed Feb 12 07:20:10 UTC 2025
On Tue, 11 Feb 2025 17:36:56 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
> > > Is the next output expected()?
> > > `public default void Test$A.setFoo(java.lang.Integer)`
> >
> >
> > It looks OK, it was properly chosen by `PropertyInfo` logic, or am I wrong? If it's OK, I will add it to the test cases.
>
> Then why the property is based on the implemented interface? For classes the method from the current class will be selected. `public default void Test$A.setFoo(java.lang.Integer)` vs `public void Test$DC.setFoo(java.lang.Number)`
I'd like to clarify this case first.
OK, we have the test:
import java.beans.IntrospectionException;
public class Test {
public interface A {
default void setFoo(Integer num) {
System.out.println(Thread.currentThread().getStackTrace()[1]);
}
}
public class D implements A {
public void setFoo(Number num) {
System.out.println(Thread.currentThread().getStackTrace()[1]);
}
}
private void run() {
var d = new D();
d.setFoo(null);
}
public static void main(String[] args) throws java.beans.IntrospectionException {
test(D.class);
System.out.println("--- run");
(new Test()).run();
}
private static void test(Class beanClass) throws IntrospectionException {
System.out.println("\nbeanClass = " + beanClass);
var info = java.beans.Introspector.getBeanInfo(beanClass, Object.class);
System.out.println(info.getBeanDescriptor());
System.out.println("--- properties");
for (var desc : info.getPropertyDescriptors()) {
System.out.println(desc.getReadMethod());
System.out.println(desc.getWriteMethod());
}
System.out.println("--- methods");
for (var desc : info.getMethodDescriptors()) {
System.out.println(desc.getMethod());
}
}
}
and the output is
java.beans.BeanDescriptor[name=Test$D; beanClass=class Test$D]
--- properties
null
public default void Test$A.setFoo(java.lang.Integer)
--- methods
public void Test$D.setFoo(java.lang.Number)
public default void Test$A.setFoo(java.lang.Integer)
--- run
Test$A.setFoo(Test.java:7)
`Test$A.setFoo()` was chosen for `d.setFoo(null)` call. And this conforms to what we see in `--- properties` chapter.
Is this a correct behavior?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23443#issuecomment-2652851052
More information about the client-libs-dev
mailing list