-
Bug
-
Resolution: Fixed
-
P4
-
7, 8
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
I found a bug in Oracle java compiler that causes "reference to ... is ambiguous" error. The same code does compile with Eclipse java compiler without any problem.
The scenario is as following:
* you have an generic interface GI with a method m using the generic (without bounds) as argument
* you have an typed (non-generic) interface TI with a method defining the same method signature but instead of the generic it uses a concret non-primitive type X.
* you have an interface CI that combines both interfaces and binds the generic to X (extends GI<X>, TI).
* also CI defines a default method that calls the method m with some argument compliant to X.
I added the minimum isolated code in the "Source code for an executable test case" field.
See also here where I discovered the problem in an open-source project:
https://github.com/m-m-m/util/issues/166
ADDITIONAL REGRESSION INFORMATION:
Works fine in Eclipse compiler.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the code submitted in "Source code for an executable test case".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should compile as both methods are setValue(java.lang.Boolean) and should not be considered ambiguous but same.
ACTUAL -
[ERROR] .../src/main/java/CombinedInterface.java:[5,5] reference to setValue is ambiguous
[ERROR] both method setValue(java.lang.Boolean) in TypedInterface and method setValue(V) in GenericInterface match
ERROR MESSAGES/STACK TRACES THAT OCCUR :
[ERROR] .../src/main/java/CombinedInterface.java:[5,5] reference to setValue is ambiguous
[ERROR] both method setValue(java.lang.Boolean) in TypedInterface and method setValue(V) in GenericInterface match
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public interface GenericInterface<V> {
void setValue(V value);
}
public interface TypedInterface {
void setValue(Boolean value);
}
public interface CombinedInterface extends GenericInterface<Boolean>, TypedInterface {
default void set(boolean value) {
setValue(Boolean.valueOf(value));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use Eclipse compiler instead.
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
I found a bug in Oracle java compiler that causes "reference to ... is ambiguous" error. The same code does compile with Eclipse java compiler without any problem.
The scenario is as following:
* you have an generic interface GI with a method m using the generic (without bounds) as argument
* you have an typed (non-generic) interface TI with a method defining the same method signature but instead of the generic it uses a concret non-primitive type X.
* you have an interface CI that combines both interfaces and binds the generic to X (extends GI<X>, TI).
* also CI defines a default method that calls the method m with some argument compliant to X.
I added the minimum isolated code in the "Source code for an executable test case" field.
See also here where I discovered the problem in an open-source project:
https://github.com/m-m-m/util/issues/166
ADDITIONAL REGRESSION INFORMATION:
Works fine in Eclipse compiler.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the code submitted in "Source code for an executable test case".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should compile as both methods are setValue(java.lang.Boolean) and should not be considered ambiguous but same.
ACTUAL -
[ERROR] .../src/main/java/CombinedInterface.java:[5,5] reference to setValue is ambiguous
[ERROR] both method setValue(java.lang.Boolean) in TypedInterface and method setValue(V) in GenericInterface match
ERROR MESSAGES/STACK TRACES THAT OCCUR :
[ERROR] .../src/main/java/CombinedInterface.java:[5,5] reference to setValue is ambiguous
[ERROR] both method setValue(java.lang.Boolean) in TypedInterface and method setValue(V) in GenericInterface match
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public interface GenericInterface<V> {
void setValue(V value);
}
public interface TypedInterface {
void setValue(Boolean value);
}
public interface CombinedInterface extends GenericInterface<Boolean>, TypedInterface {
default void set(boolean value) {
setValue(Boolean.valueOf(value));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use Eclipse compiler instead.
- duplicates
-
JDK-7028828 15.12.2.5: Confusion in rules for maximally specific method disambiguation
-
- Closed
-
- relates to
-
JDK-7028808 Incorrect ambiguity error for methods unified by generics
-
- Closed
-
-
JDK-7028828 15.12.2.5: Confusion in rules for maximally specific method disambiguation
-
- Closed
-