JDK-8175317 : javac does not issue unchecked warnings when checking method reference return types
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2017-02-21
  • Updated: 2017-05-17
  • Resolved: 2017-03-08
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.
JDK 10 JDK 9
10Fixed 9 b161Fixed
Sub Tasks
JDK-8179982 :  
Description
Initially seen here:
http://stackoverflow.com/questions/42346895/constructor-reference-no-warning-when-generics-array-is-created

Javac does not generate unchecked warnings when checking method reference return types. The issue is not limited to arrays.

import java.util.function.*;
import java.util.*;

class Test {
   void m() {
            IntFunction<List<String>[]> sls = List[]::new; //no warning
      Supplier<List<String>> sls = this::l; //no warning
   }

   List l() { return null; }
}


Comments
This is a compiler bug. The spec mandates the warning: "A compile-time unchecked warning occurs if unchecked conversion was necessary for the return type R', described above, to be compatible with the function type's return type, R, and this conversion would cause an unchecked warning in an assignment context." Unfortunately, the javac code that checks for return type compatibility does not pass any warning context and, as a result, no warning is issued.
22-02-2017