eclipse-jdt / eclipse-jdt/eclipse.jdt.core

Should explicit record component accessors share nullness of the component declaration?

Open
#3,989 1 comment 0 reactions 1 assignee Claimed by @stephan-herrmann View on GitHub
null
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

Another follow-up from #3971 e.g.,:
```java
public record R2(@NonNull String s) {
public String s() {
return null;
}
}

class test {
void m(R2 r2) {
@NonNull String s = r2.s();
}
}
```

The `@NonNull` on the record component is ignored in two locations:
* explicit accessor is incompatible with the component declaration. Should this be allowed so that even a non-null initialized component could answer `null` via its accessor?
* use of the accesor (`r2.s()`) takes absence of `@NonNull` at the explicit accessor at face value.

Need to determine the best strategy from
* enforce equal annotations on component and accessor, or,
* implicitly copy annotation from component to any explicit accessor

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.