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

generic variable length argument problem (poor diagnostic)

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: rmT116609 Date: 11/19/2003


      FULL PRODUCT VERSION :
      java version "1.4.2_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
      Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      Given a method with a method-level generic type where the parameter list is variable length in the generic, any call to the method fails. See varArg2 in code below. I am hoping this is a problem with the early release of the generics compiler and not a "feature" of 1.5.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The calls to varArg2 below cause compiler errors.




      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      cd c:/Work/Test/Collections/
      javac -classpath c:\work\115\Classlibs;..;. -sourcepath ./;../;../.. -bootclasspath C:\j2sdk1.4.2_01\adding_generics-2_2-ea\collect.jar;c:\j2sdk1.4.2_01\jre\lib\rt.jar -g -deprecation -J-Xbootclasspath/p:c:\j2sdk1.4.2_01\adding_generics-2_2-ea\gjc-rt.jar -source 1.5 -warnunchecked VarArgTest.java
      VarArgTest.java:30: varArg2<ArgType>(ArgType[]) in VarArgTest cannot be applied to (); cannot instantiate from arguments because actual and formal argument lists differ in length
          varArg2();
          ^
      VarArgTest.java:31: varArg2<ArgType>(ArgType[]) in VarArgTest cannot be applied to (java.lang.String); no instance(s) of type variable(s) ArgType exist so that argument type java.lang.String conforms to formal parameter type ArgType[]
          varArg2("Foo");
          ^
      VarArgTest.java:32: varArg2<ArgType>(ArgType[]) in VarArgTest cannot be applied to (java.lang.String,int); no instance(s) of type variable(s) ArgType exist so that argument type java.lang.String conforms to formal parameter type ArgType[]
          varArg2("Foo", 3);
          ^
      3 errors

      Compilation exited abnormally with code 1 at Wed Nov 19 15:19:28


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /**
       * VarArgTest.java
       *
       *
       * Created: Wed Nov 19 14:35:14 2003
       *
       * @author <a href="mailto: "</a>
       * @version
       */

      public class VarArgTest{
        public VarArgTest (){
          
        }
        
        public static void varArg1(Object... args) {
          System.out.println("varArg1 called with " + args.length + " parameters.");
        }

        public static <ArgType> void varArg2(ArgType... args) {
          System.out.println("varArg2 called with " + args.length + " parameters.");
        }

        public static void main(String[] args){
          varArg1();
          varArg1("Foo");
          varArg1("Foo", 3);

          varArg2();
          varArg2("Foo");
          varArg2("Foo", 3);
        }


      } // VarArgTest
      ---------- END SOURCE ----------
      (Incident Review ID: 226796)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            gafter Neal Gafter
            Reporter:
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: