Hello,
We've noticed that Introspector behavior has changed in 7u40 compared to 7u25.
Here is the example to show the difference. Let's assume that we have two
classes:
public class A {}
public class B extends A {}
And two beans:
public class BeanA
{
public void setData(A value) {}
public A getData() {return null;}
}
public class BeanB extends BeanA
{
public void setData(B value) {}
public B getData() {return null;}
}
Here BeanB overrides getData method by using covariant return type. If we run
Introspector for BeanB, then 7u25 returns PropertyType of 'data' equal to 'B',
while 7u40 reports it as 'A' instead. It seems, that in 7u40 (and later
versions) if return type of getter method can be casted to the return type of
getter with same name defined in super-class, then Introspector just uses
return type of getter in parent class.
If I understand correctly, this change is result of following fix, which was
introduced in jdk8 and then ported to 7u40:
https://bugs.openjdk.java.net/browse/JDK-7189112.
So, here is my question: is the currently observed behavior in 7u40 a desired
one, which will be kept for future java updates? Should we adapt our code to
such behavior or just wait for some changes in next updates? Well, overriding
properties in children classes (with covariant return type change) doesn't look
like a particularly good idea - and such situation was just impossible when
JavaBeans spec was originally created (it wasn't possible to override getter
with different return type until covariant returns were introduced in Java 5).
However, current behavior looks a little counter-intuitive - we have class with
pair of matching getter and setter methods, while type of property is resolved
to the getter defined in base class. And, of course, such change may break some
existing code while upgrading to the 7u40 (as it was in our case).
Thanks,
Alexey