groovy

Joint compiler does not honour JavaBean spec for boolean properties

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.5.1, 1.5.2, 1.5.3, 1.5.4
  • Fix Version/s: 1.6.6, 1.7-rc-1
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

Currently on the Java side boolean properties like "enabled" are seen as getEnabled() instead of isEnabled(). The problem is even worse because JetGroovy's joint compiler sees them as isEnabled()

Issue Links

Activity

Hide
blackdrag blackdrag added a comment -

afaik the spec says that for a boolean property the getEnabled() as well as the isEnabled() methods are valid. But we can make this clear... on http://java.sun.com/javase/technologies/desktop/javabeans/docs/spec.html is the bean spec. There you can read:

8.3.2 Boolean properties
In addition, for boolean properties, we allow a getter method to match the pattern:

public boolean is<PropertyName>();

This "is<PropertyName>" method may be provided instead of a "get<PropertyName>" method, or it may be provided in addition to a "get<PropertyName>" method. In either case, if the "is<PropertyName>" method is present for a boolean property then we will use the "is<PropertyName>" method to read the property value.

An example boolean property might be:
public boolean isMarsupial();
public void setMarsupial(boolean m);

I am speaking from what I remember here, so it might need tests to be sure, but... what groovy does not is that if the parent class is providing an is-method, and you define a property of the same name, then Groovy will not overwrite the is-method, but generate an get-method.

From the runtime side we use the bean utils provided by the jdk, so if these utils follow the specification and a boolean is-method provided we prefer it over the getter. We might have to test if we don't overwrite the method then again with the getter, but I think that is not the issue here.

We are talking about the compiler and according to the bean spec it is perfectly legal to provide a getter instead of a is-method. Even having both is legal according to the spec. So I guess I am not really understanding the problem. Both compiler do have legal output, they are just not clear which way to go.

A reason we did implement only the getter and not the is-method is, because for a user it is more easy to remember the getter only, while he would have to remember the type of the property then too and a change in a file with a custom getter becomes less local.

But a bug in terms of violation of the beans specification this is not.

Show
blackdrag blackdrag added a comment - afaik the spec says that for a boolean property the getEnabled() as well as the isEnabled() methods are valid. But we can make this clear... on http://java.sun.com/javase/technologies/desktop/javabeans/docs/spec.html is the bean spec. There you can read:
8.3.2 Boolean properties In addition, for boolean properties, we allow a getter method to match the pattern: public boolean is<PropertyName>(); This "is<PropertyName>" method may be provided instead of a "get<PropertyName>" method, or it may be provided in addition to a "get<PropertyName>" method. In either case, if the "is<PropertyName>" method is present for a boolean property then we will use the "is<PropertyName>" method to read the property value. An example boolean property might be: public boolean isMarsupial(); public void setMarsupial(boolean m);
I am speaking from what I remember here, so it might need tests to be sure, but... what groovy does not is that if the parent class is providing an is-method, and you define a property of the same name, then Groovy will not overwrite the is-method, but generate an get-method. From the runtime side we use the bean utils provided by the jdk, so if these utils follow the specification and a boolean is-method provided we prefer it over the getter. We might have to test if we don't overwrite the method then again with the getter, but I think that is not the issue here. We are talking about the compiler and according to the bean spec it is perfectly legal to provide a getter instead of a is-method. Even having both is legal according to the spec. So I guess I am not really understanding the problem. Both compiler do have legal output, they are just not clear which way to go. A reason we did implement only the getter and not the is-method is, because for a user it is more easy to remember the getter only, while he would have to remember the type of the property then too and a change in a file with a custom getter becomes less local. But a bug in terms of violation of the beans specification this is not.
Hide
blackdrag blackdrag added a comment -

since Groovy now generates the "is" and the "get" varient now, this should be no more an issue

Show
blackdrag blackdrag added a comment - since Groovy now generates the "is" and the "get" varient now, this should be no more an issue

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: