eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Eclipse incorrectly marks `@SuppressWarnings("rawtypes")` as unnecessary when javac requires it
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 49
Description
I just ran into a situation in which I had to add `@SuppressWarnings("rawtypes")` to prevent a Java 25 compiler warning, but Eclipse EE 2025-12 now says the warning suppression is unnecessary. This may be related to #4729, but it's a different issue.
I had an LLM generate this ticket, but I reviewed it.
## Summary
When a generic method returns a parameterized type based on a `Class` parameter, calling it with a raw class literal like `Set.class` produces a rawtypes warning in javac (25+). Adding `@SuppressWarnings("rawtypes")` to the local variable silences javac, but Eclipse marks this suppression as "unnecessary."
## Environment
- Eclipse version: 2025-12 (4.38.0)
- Java version: 25
- OS: Windows
```
openjdk 25 2025-09-16 LTS
OpenJDK Runtime Environment Temurin-25+36 (build 25+36-LTS)
OpenJDK 64-Bit Server VM Temurin-25+36 (build 25+36-LTS, mixed mode, sharing)
```
## Minimal Reproducible Example
```java
import java.util.Optional;
import java.util.Set;
public class RawtypesSuppressionBug {
// Generic method that returns Optional> based on Class parameter
static Optional> findContainer(Class type) {
return Optional.empty();
}
static class Container {
Optional getValue() {
return Optional.empty();
}
}
public static void main(String[] args) {
// javac warns: "found raw type: java.util.Set"
// Eclipse: no warning
final Optional withoutSuppression = findContainer(Set.class)
.flatMap(Container::getValue);
// javac: warning silenced
// Eclipse: "Unnecessary @SuppressWarnings("rawtypes")"
@SuppressWarnings("rawtypes")
final Optional withSuppression = findContainer(Set.class)
.flatMap(Container::getValue);
System.out.println(withoutSuppression);
System.out.println(withSuppression);
}
}
```
## Steps to Reproduce
1. Compile with javac (no `-Xlint:-rawtypes`):
```
javac RawtypesSuppressionBug.java
```
2. Observe javac output:
```
RawtypesSuppressionBug.java:17: warning: [rawtypes] found raw type: Set
final Optional withoutSuppression = findContainer(Set.class)
^
missing type arguments for generic class Set
where E is a type-variable:
E extends Object declared in interface Set
1 warning
```
3. Open the same file in Eclipse.
4. Observe that Eclipse shows no warning on line 17 (`withoutSuppression`), but shows "Unnecessary @SuppressWarnings("rawtypes")" on line 22 (`withSuppression`).
## Expected Behavior
Eclipse should either:
1. Produce the same rawtypes warning as javac on the unsuppressed line, making the suppression necessary, **or**
2. Not mark the suppression as unnecessary if javac requires it
## Actual Behavior
- javac produces a rawtypes warning; the suppression silences it
- Eclipse produces no rawtypes warning and marks the suppression as unnecessary
This discrepancy forces developers to choose between:
- Keeping the suppression (javac-correct, but Eclipse shows false positive)
- Removing the suppression (Eclipse-clean, but javac warns)
## Analysis
The issue appears to be that Eclipse does not consider `Set.class` (which has type `Class` where `Set` is raw) to be a rawtypes usage in this context, while javac does. The raw type flows through the generic method's return type `Optional>` where `Set` lacks type arguments.
Contributor guide
Assessment
This issue has not been assessed yet.