JDK-8061782 : Unable to compile code using wildcard generics under 8u25 but builds under 8u05
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u20,8u25
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2014-10-21
  • Updated: 2014-10-22
  • Resolved: 2014-10-22
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Darwin Wills-MacBook-Pro.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
The attached code compiles fine on 8u05 but doesn't compile on 8u20 or 8u25. I'm aware that there were changes to the handling of wildcards in 8u20 (JDK-8042338 & JDK-8042803) but I don't see anything wrong with this code.

Also, both Eclipse and IntelliJ do not display any errors when viewing this code.

REGRESSION.  Last worked in version 8u5

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached code using a version of Java after update 5.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Code should compile
ACTUAL -
Code doesn't compile

ERROR MESSAGES/STACK TRACES THAT OCCUR :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project utilities: Compilation failure
[ERROR] ... Temp.java:[8,39] incompatible types: java.util.function.Consumer<capture#1 of ?> cannot be converted to java.util.function.Consumer<? super capture#1 of ?>
[ERROR] -> [Help 1]

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.List;
import java.util.function.Consumer;

public class Temp {

    public void doWithList(final List<?> list) {
        list.stream().forEach(consumer(System.out::println));
    }

    @FunctionalInterface
    public static interface ExceptionThrowingConsumer<T> {
        void accept(T input) throws Exception;
    }

    public static <T> Consumer<T> consumer(ExceptionThrowingConsumer<T> consumer) {
        return i -> {
            try {
                consumer.accept(i);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };
    }

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The only workaround is to rewrite the code


Comments
The code compiles fine with JDK 8u5 and 8u40. It does not compile with JDK 8u20 and 8u25. Therefore, it looks like 8u40 probably has addressed the regression.
22-10-2014