{"action":"created","issue":{"url":"https://api.github.com/repos/google/auto/issues/275","labels_url":"https://api.github.com/repos/google/auto/issues/275/labels{/name}","comments_url":"https://api.github.com/repos/google/auto/issues/275/comments","events_url":"https://api.github.com/repos/google/auto/issues/275/events","html_url":"https://github.com/google/auto/issues/275","id":106977298,"number":275,"title":"AutoValue fails when a isFoo() method returns Boolean instead of boolean.","user":{"login":"dballesteros7","id":1774523,"avatar_url":"https://avatars.githubusercontent.com/u/1774523?v=3","gravatar_id":"","url":"https://api.github.com/users/dballesteros7","html_url":"https://github.com/dballesteros7","followers_url":"https://api.github.com/users/dballesteros7/followers","following_url":"https://api.github.com/users/dballesteros7/following{/other_user}","gists_url":"https://api.github.com/users/dballesteros7/gists{/gist_id}","starred_url":"https://api.github.com/users/dballesteros7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dballesteros7/subscriptions","organizations_url":"https://api.github.com/users/dballesteros7/orgs","repos_url":"https://api.github.com/users/dballesteros7/repos","events_url":"https://api.github.com/users/dballesteros7/events{/privacy}","received_events_url":"https://api.github.com/users/dballesteros7/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-17T12:53:29Z","updated_at":"2015-09-17T18:00:00Z","closed_at":"2015-09-17T18:00:00Z","body":"I believe it is because [this line](https://github.com/google/auto/blob/master/value/src/main/java/com/google/auto/value/processor/AutoValueProcessor.java#L532) only checks for boolean.class.\r\n\r\nIs there any particular reason why this doesn't check for Boolean.class as well? It would help when you have optional boolean parameters, i.e.\r\n\r\n```java\r\n\r\n@AutoValue\r\nclass Bar {\r\n  @Nullable abstract Boolean isFoo();\r\n\r\n  @AutoValue.Builder\r\n   class Builder {\r\n     abstract Builder setFoo(@Nullable Boolean foo);\r\n     abstract Bar build();\r\n   }\r\n}\r\n```\r\n\r\nMy workaround is to use boolean and always set a default builder with the value set to false, but it would be nice to be able to have the value unset and then be able to do validations in the build method, e.g. when validate parameters passed in a URL.\r\n\r\nI can send a CL if this is a reasonable request.\r\n\r\nOf course I could avoid this if I don't use the \"is\" prefix, but for some variables names this is better than \"get\" and is the convention in our code."},"comment":{"url":"https://api.github.com/repos/google/auto/issues/comments/141167493","html_url":"https://github.com/google/auto/issues/275#issuecomment-141167493","issue_url":"https://api.github.com/repos/google/auto/issues/275","id":141167493,"user":{"login":"eamonnmcmanus","id":5246810,"avatar_url":"https://avatars.githubusercontent.com/u/5246810?v=3","gravatar_id":"","url":"https://api.github.com/users/eamonnmcmanus","html_url":"https://github.com/eamonnmcmanus","followers_url":"https://api.github.com/users/eamonnmcmanus/followers","following_url":"https://api.github.com/users/eamonnmcmanus/following{/other_user}","gists_url":"https://api.github.com/users/eamonnmcmanus/gists{/gist_id}","starred_url":"https://api.github.com/users/eamonnmcmanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eamonnmcmanus/subscriptions","organizations_url":"https://api.github.com/users/eamonnmcmanus/orgs","repos_url":"https://api.github.com/users/eamonnmcmanus/repos","events_url":"https://api.github.com/users/eamonnmcmanus/events{/privacy}","received_events_url":"https://api.github.com/users/eamonnmcmanus/received_events","type":"User","site_admin":false},"created_at":"2015-09-17T18:00:00Z","updated_at":"2015-09-17T18:00:00Z","body":"It's deliberate, since we're following a subset of the [JavaBeans conventions](https://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html). There, the special `isFoo` case applies exactly to `boolean` and no other type.\r\n\r\nAs a practical matter, I think `@Nullable Boolean` is something of a code smell. Among other problems it means an unsuspecting user can write\r\n```java\r\nif (bar.isFoo()) {\r\n  ...\r\n}\r\n```\r\nwhich will blow up with a NullPointerException if `isFoo` returns null. You could indeed arrange for the value never to be null in the `build()` method, but that would lead readers of the code to wonder why it is `Boolean` and not `boolean`.\r\n\r\nAlthough it's slightly clunky, you do have a way to know whether the `foo` property was specified:\r\n```java\r\n@AutoValue\r\npublic class Bar {\r\n  public abstract boolean isFoo();\r\n\r\n  public static Builder builder() {\r\n    return new AutoValue_Bar.Builder();\r\n  }\r\n\r\n  @AutoValue.Builder\r\n  public abstract class Builder {\r\n    public abstract Builder setFoo(boolean foo);\r\n    abstract boolean isFoo();\r\n\r\n    abstract Bar autoBuild();\r\n    \r\n    public Bar build() {\r\n      try {\r\n        isFoo();\r\n      } catch (IllegalStateException e) {\r\n        setFoo(...logic_for_default_value_of_foo...);\r\n      }\r\n      return autoBuild();\r\n    }    \r\n  }\r\n}\r\n```"}}