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

javac, Gen is generating extra checkcast instructions in some corner cases

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8
    • tools
    • b08
    • Verified

      In the case of this class:

      public class Test {
              void m1(byte[] b) {}

              void m2() {
                      Object o;
                      m1((byte[])(o = null));
              }
      }

      javac generates this code for m2:

      void m2();
          descriptor: ()V
          flags:
          Code:
            stack=3, locals=2, args_size=1
               0: aload_0
               1: aconst_null
               2: dup
               3: astore_1
               4: checkcast #2 // class "[B"
               7: checkcast #2 // class "[B"
              10: invokevirtual #3 // Method m1:([B)V
              13: return
            LineNumberTable:
              line 6: 0
              line 7: 13

      The second checkcast is unnecessary.

            pgovereau Paul Govereau (Inactive)
            vromero Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: