-
Bug
-
Resolution: Unresolved
-
P4
-
8, 10, 11
-
x86_64
-
windows_10
ADDITIONAL SYSTEM INFORMATION :
This bug is present in JDK 8, 9, 10 and 11-EA releases. The bug is present on both windows and linux platforms.
A DESCRIPTION OF THE PROBLEM :
Consider the attached single class. There should be a compiler error at the line FirstClass.create(transformer.valueOf(true)).toNextClass(); , however javac compiles this code fine.
The compiler error should be that Incompatible types are returned: expected <V> actual <? extends V> .
IntelliJ and Eclipse both show this error correctly, but javac compiles fine
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Consider the class below, there should be a compiler error at the commented line. javac should not infer the upper bounds and replace it with <V>
public class BugReport {
public static class FirstClass<T> {
public static <E> FirstClass<E> create(E... elements) {
return new FirstClass<>();
}
public NextClass<T> toNextClass() {
return new NextClass<>();
}
}
public static class NextClass<T> {
public NextClass() {
}
}
public interface Transformer<V> {
V valueOf(boolean parameter);
}
public class TestImpl {
public <V> NextClass<V> test(Transformer<? extends V> transformer) {
return FirstClass.create(transformer.valueOf(true)).toNextClass(); // There should be a compiler error on this line.
}
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
there should be a compiler error at the commented line. javac should not infer the upper bounds and replace it with <V>
ACTUAL -
javac compiles fine
This bug is present in JDK 8, 9, 10 and 11-EA releases. The bug is present on both windows and linux platforms.
A DESCRIPTION OF THE PROBLEM :
Consider the attached single class. There should be a compiler error at the line FirstClass.create(transformer.valueOf(true)).toNextClass(); , however javac compiles this code fine.
The compiler error should be that Incompatible types are returned: expected <V> actual <? extends V> .
IntelliJ and Eclipse both show this error correctly, but javac compiles fine
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Consider the class below, there should be a compiler error at the commented line. javac should not infer the upper bounds and replace it with <V>
public class BugReport {
public static class FirstClass<T> {
public static <E> FirstClass<E> create(E... elements) {
return new FirstClass<>();
}
public NextClass<T> toNextClass() {
return new NextClass<>();
}
}
public static class NextClass<T> {
public NextClass() {
}
}
public interface Transformer<V> {
V valueOf(boolean parameter);
}
public class TestImpl {
public <V> NextClass<V> test(Transformer<? extends V> transformer) {
return FirstClass.create(transformer.valueOf(true)).toNextClass(); // There should be a compiler error on this line.
}
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
there should be a compiler error at the commented line. javac should not infer the upper bounds and replace it with <V>
ACTUAL -
javac compiles fine