eclipse-jdt / eclipse-jdt/eclipse.jdt.core
EEAs applied incorrectly when using "Inherit null annotations" with NonNullByDefault
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 49
Description
Given:
1. An EEA file for Map containing:
```java
class java/util/Map
get
(Ljava/lang/Object;)TV;
(Ljava/lang/Object;)T0V;
```
2. "Inherit null annotations" compiler option enabled
3. A test class with `@NonNullByDefault`
Then in the following example the compiler correctly determines that `Map#get` can return null values but incorrectly determines that `HashMap#get` or `AbstractMap#get` will always return non-null values.
```java
package test;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
public class Test {
@NonNullByDefault
public static void main(final String[] args) {
final HashMap hashmap = new HashMap<>();
if (hashmap.get("") == null) { // compiler warning: Redundant null check: comparing '@NonNull Object' against null
}
final AbstractMap abstractmap = new HashMap<>();
if (abstractmap.get("") == null) { // compiler warning: Redundant null check: comparing '@NonNull Object' against null
}
final Map map = new HashMap<>();
if (map.get("") == null) { // no warning
}
}
}
```
I am using Eclipse 2023-03 with these null analysis settings:

Contributor guide
Assessment
This issue has not been assessed yet.