JDK-8148128 : Regression: array constructor references marked as inexact
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u60,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux_redhat_6.0
  • CPU: x86
  • Submitted: 2016-01-15
  • Updated: 2016-09-26
  • Resolved: 2016-01-26
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 9
9 b104Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.32-573.3.1.el6.x86_64

A DESCRIPTION OF THE PROBLEM :
u51 javac compiles with a warning but u60 and later javac gives an error. I see no corresponding release note about change in behavior.

REGRESSION.  Last worked in version 8u51


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Ambiguity.java:14: error: reference to doSomething is ambiguous
        doSomething(Stream.of("Foo", "Bar").map(Collections::singletonList).toArray(List[]::new));
        ^
  both method doSomething(List<String>[]) in Ambiguity and method doSomething(Set<String>[]) in Ambiguity match
Note: Ambiguity.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.*;
import java.util.stream.*;

public class Ambiguity {
    public static void doSomething (List<String>[] stuff) {
        System.out.println("List Stuff");
    }

    public static void doSomething (Set<String>[] stuff) {
        System.out.println("Set Stuff");
    }

    public static void main (String[] args) {
        doSomething(Stream.of("Foo", "Bar").map(Collections::singletonList).toArray(List[]::new));
    }
}

---------- END SOURCE ----------


Comments
The regression has been introduced by JDK-8069545
25-01-2016

This is definitively a javac issue - javac does not implement the following definition correctly: "A method reference expression of the form ArrayType :: new is always exact. " Instead, javac is erroneously applying the general definition for all constructor references: "The type denoted by ClassType is not raw, or is a non-static member type of a raw type. " Hence the bug.
25-01-2016

Verified and found the regression. 8u51 - Pass 8u52 - Pass 8u60 - Fail 8u65 - Fail 8u72 - Fail 9 ea b-102 - Fail
25-01-2016