mkarneim / pojobuilder

A Java Code Generator for Pojo Builders
Other
334 stars 44 forks source link

Unused isSet properties are generated for setterless PoJo #104

Closed meseer closed 8 years ago

meseer commented 8 years ago

Given the following Pojo:

@GeneratePojoBuilder
public class Pojo {
   private final String property; 

   public Pojo(String property) {
      this.property = property;
   }

   public String getPropertry() {
      return this.property;
   }
}

PojoBuilder will generate PojoBuilder with isSet$.. properties, which are not used neither in the build() method, not anywhere else. FindBugs will report this as a UrF: Unread field

Expected: no unused field generated and FindBugs happy with a autogenerated code.

mkarneim commented 8 years ago

These fields are made to be used by the "build" method in order to check if the property value was explicitly set. See AddressBuilder for an example. In you sample the check is not necessary since the property is passed to the pojo's constructor anyway.

Additionally the isSet-property is declared as protected field so that it can be used by any subclass of the builder. PB can't know if you are planning to use it or not. So I can't remove it just for the sake that FindBugs is fine with it. Anyway I would suggest that you configure FindBugs to not check generated code.