JDK-8055514 : Wrong, confusing error when non-static varargs referenced in static context
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u5,8u11
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_8
  • CPU: x86
  • Submitted: 2014-08-20
  • Updated: 2015-06-04
  • Resolved: 2014-09-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 8 JDK 9
8u40Fixed 9 b31Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.8.0_05

ADDITIONAL OS VERSION INFORMATION :
Windows 8.1 Update 1 (6.3.9600)

A DESCRIPTION OF THE PROBLEM :
When passing an array to a non-static method that takes in varargs of the same type from a static context, the error message says something like:

method methodName in class Clazz cannot be applied to given types;
  required: Object[]
  found: Object[]
  reason: varargs mismatch; Object[] cannot be converted to Object

This can impede progress because it does not accurately describe the issue at hand

REGRESSION.  Last worked in version 6u45

ADDITIONAL REGRESSION INFORMATION: 
1.8.0_05, 1.8.0_11 both produce this bug. Higher versions not tested, some lower versions tested and do not produce this.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
https://stackoverflow.com/revisions/25394998/1

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Something similar to the following error message is given:

non-static method methodName(Object...) cannot be referenced from a static context
ACTUAL -
Something similar to the following error message is given:

method methodName in class Clazz cannot be applied to given types;
  required: Object[]
  found: Object[]
  reason: varargs mismatch; Object[] cannot be converted to Object

ERROR MESSAGES/STACK TRACES THAT OCCUR :
method methodName in class Clazz cannot be applied to given types;
  required: Object[]
  found: Object[]
  reason: varargs mismatch; Object[] cannot be converted to Object

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class PrimitiveVarArgs
{
    public static void main(String[] args)
    {
        int[] ints = new int[]{1, 2, 3, 4, 5};
        prints(ints);
    }

    void prints(int... ints)
    {
        for(int i : ints)
            System.out.println(i);
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
add "static" to the non-static method and pretend the error never happened


Comments
Label escape-old is added, since according to Maurizio's comment: "This is caused by the new error recovery logic that has been introduced in JDK 8".
07-04-2015

ManualVerify: Bug verified manually in promoted results for build JDK9-b31
18-09-2014

This is caused by the new error recovery logic that has been introduced in JDK 8. The logic always tries to return the 'best' error message given a method call - note that we can typically pick from 3 error messages, as an overload process is composed by 3 steps. The last error message is typically spurious, as it involves varargs - and should only be preferred if the method call is indeed a varargs method call. If not, the previous errors usually retain much more info than the last. Here it seems that javac fails to see that, and only display the varargs-related message which is of little use.
01-09-2014