FULL PRODUCT VERSION :
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+161)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+161, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
not OS specific (currently reproducing on Darwin syrah 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64)
A DESCRIPTION OF THE PROBLEM :
See the code, compiles with JDK8 alright, fails with latest JDK9 161.
/Users/rhusar/wildfly/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/JChannelFactory.java:[68,13] error: no suitable method found for addProtocols(List<Object>)
method ProtocolStack.addProtocols(Protocol...) is not applicable
(varargs mismatch; inference variable R has incompatible bounds
equality constraints: List<T#2>
upper bounds: Protocol,Object)
method ProtocolStack.addProtocols(List<Protocol>) is not applicable
(argument mismatch; inference variable T#2 has incompatible bounds
equality constraints: Protocol
lower bounds: Object)
where R,A,T#1,T#2 are type-variables:
R extends Object declared in method <R,A>collect(Collector<? super T#1,A,R>)
A extends Object declared in method <R,A>collect(Collector<? super T#1,A,R>)
T#1 extends Object declared in interface Stream
T#2 extends Object declared in method <T#2>toList()
[ERROR] /Users/rhusar/wildfly/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/JChannelFactory.java:[72,76] error: cannot find symbol
symbol: method createProtocol(ProtocolStackConfiguration)
location: variable pc of type Object
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the test attached compiles OK like jdk9
ACTUAL -
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/rhusar/git/jdk9typebug/src/main/java/JChannelFactory.java:[14,14] no suitable method found for addProtocols(java.util.List<java.lang.Object>)
method JChannelFactory.ProtocolStack.addProtocols(JChannelFactory.Protocol...) is not applicable
(varargs mismatch; inference variable R has incompatible bounds
equality constraints: java.util.List<T>
upper bounds: JChannelFactory.Protocol,java.lang.Object)
method JChannelFactory.ProtocolStack.addProtocols(java.util.List<JChannelFactory.Protocol>) is not applicable
(argument mismatch; inference variable T has incompatible bounds
equality constraints: JChannelFactory.Protocol
lower bounds: java.lang.Object)
[ERROR] /Users/rhusar/git/jdk9typebug/src/main/java/JChannelFactory.java:[17,77] cannot find symbol
symbol: method createProtocol(JChannelFactory.ProtocolStackConfiguration)
location: variable pc of type java.lang.Object
[INFO] 2 errors
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author Radoslav Husar
*/
public class JChannelFactory {
void createChannel() {
ProtocolStackConfiguration configuration = new ProtocolStackConfiguration();
ProtocolStack stack = new ProtocolStack();
stack.addProtocols(Stream.of(
Stream.of(configuration.getTransport()),
configuration.getProtocols().stream()
).flatMap(Function.identity()).filter(Objects::nonNull).map(pc -> pc.createProtocol(configuration)).collect(Collectors.toList()));
}
public abstract static class Protocol {
}
public interface ProtocolConfiguration<P extends Protocol> {
P createProtocol(ProtocolStackConfiguration stackConfiguration);
}
static class ProtocolStackConfiguration {
ProtocolConfiguration<? extends TP> getTransport() {
return null;
}
List<ProtocolConfiguration<? extends Protocol>> getProtocols() {
return null;
}
}
static class TP extends Protocol {
}
public static class ProtocolStack {
public ProtocolStack addProtocols(Protocol... prots) {
return this;
}
public ProtocolStack addProtocols(List<Protocol> prots) {
return this;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
explicitly cast:
.map(pc -> ((ProtocolConfiguration)pc).createProtocol(configuration))