google / google/auto

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

Open
#1,931 7 comments 0 reactions 1 assignee Claimed by @eamonnmcmanus View on GitHub
Component: value P3
Dominant language
Java
Stars
10.6k
Forks
1.2k
Avg merge
6h 32m
Merged PRs (30d)
13

Description

Consider this use of AutoBuilder:

```java
@AutoBuilder(callMethod = "of")
public abstract static class Builder {

@Override
public abstract Builder setValue(T value);

...
}
```
(distilled from https://github.com/apache/beam/pull/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`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.