Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8065312

javac incorrectly reports cause of error on non-static varargs call from static

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u11
    • tools
    • x86
    • windows_8

      FULL PRODUCT VERSION :
      java version "1.8.0_11"
      Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      A DESCRIPTION OF THE PROBLEM :
      javac incorrectly reports the cause of a compilation error in the included source. The source attempts to call a non-static method from a static context. This occurs when attempting to call a varargs method with an array of the varargs type.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Attempt to compile the included source.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Test.java:5: error: non-static method prints(int...) cannot be referenced from a static context
              prints(ints);
              ^
      1 error
      ACTUAL -
      Test.java:5: error: method prints in class Test cannot be applied to given types;
              prints(ints);
              ^
        required: int[]
        found: int[]
        reason: varargs mismatch; int[] cannot be converted to int
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test {
          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 ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: