JDK-8152894 : Incorrect raw type warning for method reference
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u60,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2016-03-28
  • Updated: 2016-05-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_majorUnresolved
Related Reports
Relates :  
Description
The following produces 3 raw type warnings (with -Xlint), one for each method reference:

import java.util.stream.Stream;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;

public class RawMethodRef {

    void test1(Stream<? extends Class<String>> stream) {
        stream.filter(Class::isInterface);
    }

    void test2(Stream<String> stream, Function<String, ? extends Optional<String>> f) {
        stream.map(f).filter(Optional::isPresent);
    }

    void test3(Stream<? extends Supplier<String>> stream) {
        stream.map(Supplier::get).filter(s -> s.isEmpty());
    }

}

There should be no warning, because the type argument in each case is inferred. (test3 demonstrates that, in fact, the type argument is correctly inferred and becomes the type of 's'.)

The warning goes away if I remove the wildcards, so the problem is in the handling of capture variables.

JDK-8039214 had the side-effect of introducing the warning in test2 -- prior to that (e.g., in JDK 8), only test1 and test3 produce warnings.