Bug 522380 - [compiler] The method is ambiguous error if method is overridden with same signature
Summary: [compiler] The method is ambiguous error if method is overridden with same si...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2017-09-15 14:32 EDT by Jörg Hohwiller CLA
Modified: 2023-05-29 12:39 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Hohwiller CLA 2017-09-15 14:32:29 EDT
I found a regression bug with the Eclipse compiler causing an falsely ambiguous method error. This error did not show up with Neon but arises with Oxygen.

> Eclipse IDE for Java Developers
> Version: Oxygen Release (4.7.0)
> Build id: 20170620-1800
> Eclipse Java Development Tools 3.13.0.v20170612-0950

As a workaround I had to remove an overridden method from an interface while the overridden method did not change the signature but was just for the purpose to extend the JavaDoc. However with the overridden method being present, I get the error.
This is the commit where I removed the method:
https://github.com/m-m-m/util/commit/95d2b9ea5ac8d9ce2959a0becae429bca4353b5c

Here is the super-interface that initially declares the method:
https://github.com/m-m-m/util/blob/95d2b9ea5ac8d9ce2959a0becae429bca4353b5c/core/src/main/java/net/sf/mmm/util/value/api/SimpleValueConverter.java

Here is the line of code that is causing the error when the method is overridden:
https://github.com/m-m-m/util/blob/95d2b9ea5ac8d9ce2959a0becae429bca4353b5c/core/src/main/java/net/sf/mmm/util/lang/base/StringUtilImpl.java#L482

The exact error message from Eclipse compiler in this line 482 is:
The method convert(capture#3-of ? super String, Object, Class<E>) is ambiguous for the type ValueConverter<capture#3-of ? super String,capture#4-of ? super E>

This is obviously an error in the Eclipse compiler.

I started the discussion at https://www.eclipse.org/forums/index.php/m/1772504/#msg_1772504 but as always the users have present the bugs on the silver dish. I hope you will not request an isolated test case integrated via JUnit as pull request to the Eclipse compiler project to proceed :)
Comment 1 Stephan Herrmann CLA 2017-09-15 16:03:34 EDT
Thanks for the report, but without a self-contained example I simply can't make a promise when we will have the time to investigate.
Comment 2 Jörg Hohwiller CLA 2017-09-15 16:44:11 EDT
I searched for related issues and this one comes close:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=480541
In case it would be a real duplicate then the fact of overriding does not actually matter but only that two methods with the same name and the same number or arguments that only differ in the raw type of an argument may cause the problem.
Comment 3 Jörg Hohwiller CLA 2017-09-15 16:48:31 EDT
> differ in the raw type of an argument

that is a ParameterizedType.

In my case Class<T> vs. GenericType<T> in case of bug #480541 Predicate<? super SUB> vs. Function<? super SUB, T>. For matching methods of course one would expect the raw type to be more relevant than the type parameters.
Comment 4 Fabio Mendes CLA 2019-06-17 13:39:37 EDT
Hi Guys,

    some news about this BUG, I have the same issue.


Tks...
Comment 5 Stephan Herrmann CLA 2019-06-17 15:41:39 EDT
Reduced example:

//---
import java.lang.reflect.Type;

interface GenericType<T> extends Type { }
interface SimpleValueConverter<SOURCE, TARGET> {
	<T extends TARGET> T convert(SOURCE value, Object valueSource, Class<T> targetClass);
}
interface ValueConverter<SOURCE, TARGET> extends SimpleValueConverter<SOURCE, TARGET> {
	@Override
	<T extends TARGET> T convert(SOURCE value, Object valueSource, Class<T> targetClass);
	<T extends TARGET> T convert(SOURCE value, Object valueSource, GenericType<T> targetType);
}
public class StringUtilImpl {
  public <E> void fromSeparatedString(CharSequence separatedString, ValueConverter<? super String, ? super E> converter, Class<E> type) {
    String elementString = "";
    E element = converter.convert(elementString, separatedString, type);
  }
}
//---

This is accepted by current ecj at compliance 1.8 or greater

History:
- was accepted at 1.7+ up until 4.7M6
- rejected since 4.7M7
- accepted at 1.8+ starting from 4.8M5, but still rejected at 1.7

To be honest the know-how about overloading with type inference in Java 7 is dwindling in the JDT team. I could help if the bug exists still at compliance 1.8, but it doesn't.

Ergo: please consider upgrading your project to a recent version.


(In reply to Jörg Hohwiller from comment #0)
> This is obviously an error in the Eclipse compiler.

Please never use the word "obvious" in the context of type inference plus overloading (unless you can within a few minutes pin point the rule in JLS which is violated by our implementation).

Marking as 'helpwanted'.
Comment 6 Eclipse Genie CLA 2021-06-07 07:54:12 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 7 Vikas Chandra CLA 2021-06-07 08:07:08 EDT
Works at 1.8 compliance or later. Issue with 1.7 compliance.

Checked again on
Version: 2021-06 (4.20)
Build id: I20210602-1800
Comment 8 Eclipse Genie CLA 2023-05-29 12:39:15 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.