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

Support multiple external annotation locations

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

Description

I am getting a spurious Null Analysis warning with method references that call a NonNull return value.

I have all Null Analysis options in Java | Compiler | Errors/Warnings preferences set as Warning apart from "Missing @NonNullByDefault annotation" set as Ignore. All checkboxes checked.

I have `eea-all-2.4.0.jar` set for JRE External Annotations with JDK v21 as the JRE system library.

There seems to be no way to have this not produce a warning.

Example code:

```
package eclipse_test_samples;

import java.util.Comparator;
import java.util.List;

import org.eclipse.jdt.annotation.NonNull;

public class CompareLambdaWarning {

public static class Fruit {

@NonNull String fruitName;

public Fruit(@NonNull String aName) {
fruitName = aName;
}

@NonNull String getName() {
return fruitName;
}
}

public static void sortFruits(@NonNull List<@NonNull Fruit> aFruitList) {
// Spurious warning
// Null type safety (type annotations): The expression of type 'Comparator'
// needs unchecked conversion to conform to '@NonNull Comparator'
aFruitList.sort(Comparator.comparing(Fruit::getName));
}

public static void reverseSortFruits(@NonNull List<@NonNull Fruit> aFruitList) {
// No warning here - this works fine
aFruitList.sort(Comparator.comparing(Fruit::getName).reversed());
}

}
```

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.