FieldMissingNullable doesn't complain when variable is not initialized
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
# Current behavior
With FieldMissingNullable turned on and the following code:
```java
import java.time.OffsetDateTime;
public class Clazz {
private OffsetDateTime closeTimestamp = null;
public Clazz() {
// Do nothing
}
public OffsetDateTime getCloseTimestamp() {
return closeTimestamp;
}
public void setCloseTimestamp(OffsetDateTime closeTimestamp) {
this.closeTimestamp = closeTimestamp;
}
}
```
We get the following warnings:
```
[FieldMissingNullable] Field is assigned (or compared against) a definitely null value but is not annotated @Nullable
(see https://errorprone.info/bugpattern/FieldMissingNullable)
Did you mean 'private @Nullable OffsetDateTime closeTimestamp = null;'?
```
But when we remove the explicit `null` assignment on class startup, the warning goes away, even tho the default value for a non initialized Object variable is `null`
# Expected behavior
When:
* Variable is an object (not primitive)
* Variable is not initialized when declared
* No assignment is made in constructors
We should also get a warning:
```
[FieldMissingNullable] Field is assigned (or compared against) a definitely null value but is not annotated @Nullable
(see https://errorprone.info/bugpattern/FieldMissingNullable)
Did you mean 'private @Nullable OffsetDateTime closeTimestamp;'?
```
Contributor guide
Assessment
This issue has not been assessed yet.