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

ECJ accepts ambiguous method call between concrete parameter and bounded type variable while javac rejects as ambiguous

Open
#4,357 2 comments 0 reactions 0 assignees View on GitHub
corner case performance wontfix
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 a method invocation that could apply to both a concrete-parameter method (`specializedMethod(String)`) and a generic method with a bounded type variable (` specializedMethod(U)`), ECJ and javac exhibit divergent behavior:

- javac rejects the code with a compile-time error, reporting that the method reference is ambiguous.
- ECJ accepts the code without error or warning, silently selecting one of the overloaded methods.

## Test program:
```java
public class Test {
public static void main(String[] args) {
TemplateClass instance = new TemplateClass<>();
instance.specializedMethod("test");
}
}

class TemplateClass {

public void specializedMethod(String value) {
}

public void specializedMethod(U value) {
}
}
```

Using javac it will have an error:
```bash
javac Test.java
```
```bash
Test.java:4: error: reference to specializedMethod is ambiguous
instance.specializedMethod("test");
^
both method specializedMethod(String) in TemplateClass and method specializedMethod(U) in TemplateClass match
where U,T are type-variables:
U extends T declared in method specializedMethod(U)
T extends Object declared in class TemplateClass
1 error
```

However, ecj accepts it with no output:
```bash
java -jar ecj-4.37M3.jar -21 Test.java
# No output
```

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.