mkarneim / pojobuilder

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

Unspecified Optional Property is set to null instead of Optional.absent() #142

Closed Adrodoc closed 6 years ago

Adrodoc commented 6 years ago

This Bug was intruduced in #139 to fix #134, but the code suggested in #134 was not entirely correct. When building a Pojo with an optional Property like this:

public class Pojo {
  public Pojo(Optional<Integer> myInt) {
    // ...
  }
}

the constructor/factory method should be called with null if and only if PojoBuilder.withMyInt((Integer) null) or PojoBuilder.withMyInt((Optional<Integer>) null) was called. As of version 4.0.0 the constructor/factory method is also called with null if myInt was never specified. This is a bug, because it should be set to Optional.absent() instead. This causes the bug.