eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Eclipse does not properly override the nullability of the annotations
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
### Summary
The nullability annotation `@Nullable` given on the `method1()` does not override the `@Nonnull` on the type argument `T`
### Expected results:
- On line 12, there should be a warning about a null pointer dereference:
`Potential null pointer access: The variable str2 may be null at this location`
- There should be no warnings on line 11
### Actual results:
There are no null analysis warnings on line 12, but there is a warning on line 11:
`Null type mismatch: required '@Nonnull String' but the provided value is null`
### Null analysis settings
| Setting | Value |
|---------------------------------------------------------------------|---------|
| Null pointer access | Error |
| Potential null pointer access | Error |
| Redundant null check | Warning |
| Include 'assert' in null analysis | True |
| Enable annotation-based null analysis | True |
| Violation of null specification | Error |
| Conflict between null annotations and null inference | Error |
| Unchecked conversion from non-annotated to `@NonNull` type | Warning |
| Unsafe conversion of annotated type to less-annotated type | Info |
| Problems detected by pessimistic analysis for free type variables | Warning |
| Unsafe `@Nonnull` interpretation of free type variable from library | Warning |
| Redundant null annotation | Warning |
| `@Nonnull` parameter not annotated in overriding method | Warning |
| Missing `@NonNullByDefault` annotation on package | Warning |
| Inherit null annotations | True |
| Enable syntactic null analysis for fields | True |
| Search for external annotations in all build path locations | True |
#### Nullability annotations
| A\T | Primary | Secondary |
|---------------------|--------------------------------------------------|----------------------------------------------------------------------------|
| `@Nonnull` | `javax.annotation.Nonnull` | `org.checkerframework.checker.nullness.qual.NonNull` |
| `@Nullable` | `javax.annotation.Nullable` | `org.checkerframework.checker.nullness.qual.Nullable` |
| `@NonNullByDefault` | `javax.annotation.ParametersAreNonnullByDefault` | `org.checkerframework.checker.nullness.qual.ParametersAreNonnullByDefault` |
### Example using Google's [ErrorProne](https://errorprone.info/index):
```java
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ClassA<@Nonnull T> {
public @Nullable T method1(@Nullable T input){
return input;
}
public static void main(String[] args){
ClassA objA = new ClassA<>();
String str = null;
//🡓inferred nonnull, expected nullable, warning on the input, even though it is marked nullable🡓
String str2 = objA.method1(str);
int len = str2.length(); //no error reported, even though this method would fail with a NPE
}
}
```
#### NPE thrown by the example:
```
Exception in thread "main" java.lang.NullPointerException
at ClassA.main(ClassA.java:12)
```
Contributor guide
Assessment
This issue has not been assessed yet.