google / auto

A collection of source code generators for Java.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AutoValue generates invalid code, constructor not validated

h908714124 opened this issue · comments

Consider the following class

@AutoValue
abstract class Foo {
    Foo(String bar) {
    }
    abstract String hello();
}

AutoValue should validate this class and fail with an error message. Instead it generates the following invalid constructor:

  AutoValue_Foo(
      String hello) {
    if (hello == null) {
      throw new NullPointerException("Null hello");
    }
    this.hello = hello;
  }

This is a compile error. The constructor is invalid because AutoValue_Foo extends Foo, and there is no default constructor in Foo.

This seems like the kind of thing that @eamonnmcmanus often fixes instantly, but let's see what he thinks :)

Yes, we already have a number of explicit checks for things that we know will lead to uncompilable generated code, such as a non-static nested @AutoValue class, and this one would make sense on the same lines.