FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]
A DESCRIPTION OF THE PROBLEM :
Platform#getPlugins returns List<Object> when the specified return type is List<PluginSnapshot> when using the raw Platform type.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Setup the test code and refer to the for loop in the Main class.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Platform#getPlugins returns List<PluginSnapshot>
ACTUAL -
Platform#getPlugins returns List<Object>
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Main.java
Error(5,57) java: incompatible types: java.lang.Object cannot be converted to PluginSnapshot
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public interface Player {
UUID getUniqueId();
}
public interface PluginSnapshot {
String name();
}
public interface Platform<P extends Player> {
List<P> getPlayers();
List<PluginSnapshot> getPlugins();
}
public class Main {
public static void main(String... args) {
Platform platform = null;
for (PluginSnapshot plugin : platform.getPlugins()) {
// ...
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Specifying Platform<?> instead of Platform results in the correct behavior.
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]
A DESCRIPTION OF THE PROBLEM :
Platform#getPlugins returns List<Object> when the specified return type is List<PluginSnapshot> when using the raw Platform type.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Setup the test code and refer to the for loop in the Main class.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Platform#getPlugins returns List<PluginSnapshot>
ACTUAL -
Platform#getPlugins returns List<Object>
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Main.java
Error(5,57) java: incompatible types: java.lang.Object cannot be converted to PluginSnapshot
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public interface Player {
UUID getUniqueId();
}
public interface PluginSnapshot {
String name();
}
public interface Platform<P extends Player> {
List<P> getPlayers();
List<PluginSnapshot> getPlugins();
}
public class Main {
public static void main(String... args) {
Platform platform = null;
for (PluginSnapshot plugin : platform.getPlugins()) {
// ...
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Specifying Platform<?> instead of Platform results in the correct behavior.