You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have detected a very strange edge-case with getter/setter generation if the second character of a field name is upper-case.
Example:
public class MyBean {
private String aBc;
}
If you generate getters and setters with CobiGen you will get getABc and setABc what makes sense to me. However, IDEs like Eclipse or IntelliJ will instead generate getaBc and setaBc in this case. What seems like a bug in these IDEs has actually been implemented on purpose as a feature.
The actual problem is derived from the fact that Java Beans specification wanted to support UPPERCASE field names for abbreviations such as XML so that getXML() would make the java.beans.Introspector to derrive the field name XML instead of xML in decapitalize method (see links below). However, the implementation in java.beans.Introspector was messed and only considers the second character (see links below). Therefore getABc() would derrive to the field name ABc but the field name was actually aBc in our example.
Of course you could also argue that the field name of our example could have also initially been ABc. However, Java conventions suggests to start field names with a lower case letter. Then you could also argue that a field should never be named XML and this excuse in the Java Bean Specification does not make any sense at all. To be honest I have to admit that you are perfectly right.
However, java.beans.Introspector has been released decades ago and is unlikely to ever change. From that mistake common IDEs have implemented this bug as a feature into their products. So even though it is completely sick and nonsense we can and should not fight against JDK, Eclipse and IntelliJ if they all belive in the same thing.
Anyhow, what might be considered is that most people are not aware of this nonsense and most open-source bean introspection frameworks not based on java.beans.Introspector will therefore not contain this "bug" as a "feature". In general we should avoid naming fields such that the second character is capitalized to entirely get around this problem. Java is messed up in this regard.
We have detected a very strange edge-case with getter/setter generation if the second character of a field name is upper-case.
Example:
If you generate getters and setters with CobiGen you will get
getABc
andsetABc
what makes sense to me. However, IDEs like Eclipse or IntelliJ will instead generategetaBc
andsetaBc
in this case. What seems like a bug in these IDEs has actually been implemented on purpose as a feature.The actual problem is derived from the fact that Java Beans specification wanted to support UPPERCASE field names for abbreviations such as
XML
so thatgetXML()
would make thejava.beans.Introspector
to derrive the field nameXML
instead ofxML
indecapitalize
method (see links below). However, the implementation injava.beans.Introspector
was messed and only considers the second character (see links below). ThereforegetABc()
would derrive to the field nameABc
but the field name was actuallyaBc
in our example.Of course you could also argue that the field name of our example could have also initially been
ABc
. However, Java conventions suggests to start field names with a lower case letter. Then you could also argue that a field should never be namedXML
and this excuse in the Java Bean Specification does not make any sense at all. To be honest I have to admit that you are perfectly right.However,
java.beans.Introspector
has been released decades ago and is unlikely to ever change. From that mistake common IDEs have implemented this bug as a feature into their products. So even though it is completely sick and nonsense we can and should not fight against JDK, Eclipse and IntelliJ if they all belive in the same thing.Anyhow, what might be considered is that most people are not aware of this nonsense and most open-source bean introspection frameworks not based on
java.beans.Introspector
will therefore not contain this "bug" as a "feature". In general we should avoid naming fields such that the second character is capitalized to entirely get around this problem. Java is messed up in this regard.Sources:
The text was updated successfully, but these errors were encountered: