-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 9
-
x86_64
-
linux
FULL PRODUCT VERSION :
$ ~/bin/jdk1.8.0_112/bin/javac -version
javac 1.8.0_112
$ ~/bin/jdk1.8.0_112/bin/java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
3.13.0-100-generic #147-Ubuntu SMP Tue Oct 18 16:48:51 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
private static void test() {
Stream.empty()
.filter(o -> o instanceof List)
.map(o -> (List) o)
.flatMap(l -> l.stream())
.filter(o -> o instanceof String).<String>map(o -> (String) o)
.forEach((String s) -> someString(s));
}
private static void someString(String s) {
// do nothing
}
The code above compiles with the eclipse compiler, but not the jdk compiler.
The following compiles:
private static void test() {
Stream.empty()
.filter(o -> o instanceof String).<String>map(o -> (String) o)
.forEach((String s) -> someString(s));
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
$ java -jar ~/bin/eclipse-mars/plugins/org.eclipse.jdt.core_3.11.2.v20160128-0629.jar -8 ./Test.java # No Errors
$ ~/bin/jdk1.8.0_112/bin/javac -Xdiags:verbose ./Test.java
./Test.java:15: error: method forEach in interface Stream<T> cannot be applied to given types;
.forEach((String s) -> someString(s));
^
required: Consumer
found: (String s)[...]ng(s)
reason: argument mismatch; incompatible parameter types in lambda expression
where T is a type-variable:
T extends Object declared in interface Stream
1 error
ERROR MESSAGES/STACK TRACES THAT OCCUR :
./Test.java:15: error: method forEach in interface Stream<T> cannot be applied to given types;
.forEach((String s) -> someString(s));
^
required: Consumer
found: (String s)[...]ng(s)
reason: argument mismatch; incompatible parameter types in lambda expression
where T is a type-variable:
T extends Object declared in interface Stream
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.List;
public class Test {
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void test() {
Stream.empty()
.filter(o -> o instanceof List)
.map(o -> (List) o)
.flatMap(l -> l.stream())
.filter(o -> o instanceof String).<String>map(o -> (String) o)
.forEach((String s) -> someString(s));
}
private static void someString(String s) {
}
public static void main(String[] args) {
test();
}
}
---------- END SOURCE ----------
$ ~/bin/jdk1.8.0_112/bin/javac -version
javac 1.8.0_112
$ ~/bin/jdk1.8.0_112/bin/java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
3.13.0-100-generic #147-Ubuntu SMP Tue Oct 18 16:48:51 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
private static void test() {
Stream.empty()
.filter(o -> o instanceof List)
.map(o -> (List) o)
.flatMap(l -> l.stream())
.filter(o -> o instanceof String).<String>map(o -> (String) o)
.forEach((String s) -> someString(s));
}
private static void someString(String s) {
// do nothing
}
The code above compiles with the eclipse compiler, but not the jdk compiler.
The following compiles:
private static void test() {
Stream.empty()
.filter(o -> o instanceof String).<String>map(o -> (String) o)
.forEach((String s) -> someString(s));
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
$ java -jar ~/bin/eclipse-mars/plugins/org.eclipse.jdt.core_3.11.2.v20160128-0629.jar -8 ./Test.java # No Errors
$ ~/bin/jdk1.8.0_112/bin/javac -Xdiags:verbose ./Test.java
./Test.java:15: error: method forEach in interface Stream<T> cannot be applied to given types;
.forEach((String s) -> someString(s));
^
required: Consumer
found: (String s)[...]ng(s)
reason: argument mismatch; incompatible parameter types in lambda expression
where T is a type-variable:
T extends Object declared in interface Stream
1 error
ERROR MESSAGES/STACK TRACES THAT OCCUR :
./Test.java:15: error: method forEach in interface Stream<T> cannot be applied to given types;
.forEach((String s) -> someString(s));
^
required: Consumer
found: (String s)[...]ng(s)
reason: argument mismatch; incompatible parameter types in lambda expression
where T is a type-variable:
T extends Object declared in interface Stream
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.List;
public class Test {
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void test() {
Stream.empty()
.filter(o -> o instanceof List)
.map(o -> (List) o)
.flatMap(l -> l.stream())
.filter(o -> o instanceof String).<String>map(o -> (String) o)
.forEach((String s) -> someString(s));
}
private static void someString(String s) {
}
public static void main(String[] args) {
test();
}
}
---------- END SOURCE ----------