Skip to content

AutoBuilder with a generic parameter should be parametric in underlying type's nullability #1931

@kennknowles

Description

@kennknowles

Consider this use of AutoBuilder:

@AutoBuilder(callMethod = "of")
public abstract static class Builder<T> {

  @Override
  public abstract Builder<T> setValue(T value);

  ...
} 

(distilled from apache/beam#34902 but I will likely have changed it with a workaround by the time you click)

The type parameter T can legitimately be instantiated with any nullability: @NonNull String, @Nullable String, etc. But the generated builder class throws NullPointerException in response to setValue(null). Instead, the builder class should be fully agnostic as to the nullability (or other qualifiers) for type T.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions