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

ECJ and javac disagree on generic type bound checking for raw types

Open
#4,353 1 comment 0 reactions 0 assignees View on GitHub
rawtypes
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

## ECJ Version:
```bash
Eclipse Compiler for Java(TM) v20250814-1944, 3.43.0, Copyright IBM Corp 2000, 2020. All rights reserved.
```

## Javac Version:
```bash
javac 21.0.8
```

## Description:
When compiling the following Java code, ECJ and javac exhibit different behaviors. Javac rejects the code with a compilation error, while ECJ accepts it with only warnings.

Is there any bug in one compiler? Thanks for your insight.

## Test program:
```java
public class Test {

public static void main(String[] args) {
TemplateClass instance = new TemplateClass<>();
}
}

interface SomeTemplate {

void process(T value);
}

class TemplateClass> {
}
```

Using javac it will have an error:
```bash
javac Test.java
```
```bash
Test.java:4: error: type argument SomeTemplate is not within bounds of type-variable TemplateType
TemplateClass instance = new TemplateClass<>();
^
where TemplateType is a type-variable:
TemplateType extends SomeTemplate declared in class TemplateClass
1 error
```

However, ecj only have some warnings:
```bash
java -jar ecj-4.37M3.jar -21 Test.java
```
```bash
----------
1. WARNING in Test.java (at line 4)
TemplateClass instance = new TemplateClass<>();
^^^^^^^^^^^^
SomeTemplate is a raw type. References to generic type SomeTemplate should be parameterized
----------
2. WARNING in Test.java (at line 4)
TemplateClass instance = new TemplateClass<>();
^^^^^^^^
The value of the local variable instance is not used
----------
2 problems (2 warnings)
```

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.