AutoBuilder with a generic parameter should be parametric in underlying type's nullability
Author: kennknowlesCreated Jun 18, 2025Updated Feb 18, 2026
LabelsComponent: valueP3
Consider this use of AutoBuilder:
@AutoBuilder(callMethod = "of")
public abstract static class Builder<T> {
@Override
public abstract Builder<T> 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.
Source: google/auto