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

Clone() on arrays compiled incorrectly

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      mantis
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Consider:

      class ArrayClone {

        public static void main(String[] args) {
          args.clone();
        }
      }

      Compiling this with javac (1.3 version) and running javap on the resulting class
      file, we get:

      javap -c ArrayClone
      Compiled from ArrayClone.java
      class ArrayClone extends java.lang.Object {
          ArrayClone();
          public static void main(java.lang.String[]);
      }

      Method ArrayClone()
         0 aload_0
         1 invokespecial #1 <Method java.lang.Object()>
         4 return

      Method void main(java.lang.String[])
         0 aload_0
         1 invokevirtual #2 <Method java.lang.Object clone()>
         4 pop
         5 return


      Note that the call to clone refers to Object rather than to the array type
      String[]. This is wrong under both old and new JLS rules for compilation.
      This only matters for illegal programs, so it is not a big deal.

      gilad.bracha@eng 2000-04-12

        Attachments

          Activity

            People

            Assignee:
            gafter Neal Gafter
            Reporter:
            gbrachasunw Gilad Bracha (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: