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

Class reference duplicates in constant pool

XMLWordPrintable

    • b15
    • Verified

      FULL PRODUCT VERSION :
      java version " 1.7.0_17 "
      Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      generic

      A DESCRIPTION OF THE PROBLEM :
      After compiling a class with javac and decompiling it with javap I can see duplicates of certain class references in the constant pool section, these classes are always mentioned in method StackMapTables. From the duplicated references always the first one is used only later on in the class. Despite the runtime can work with this but these references are completely unnecessary.

      $ javap -v Duplicates.class | grep " = Class "
          #2 = Class #22 // java/lang/StringBuilder
          #7 = Class #26 // Duplicates
          #8 = Class #27 // java/lang/Object
        #16 = Class #22 // java/lang/StringBuilder <- never used
        #17 = Class #26 // Duplicates <- never used
        #18 = Class #28 // java/lang/String

      REGRESSION. Last worked in version 5.0

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the given example source with javac and decompile it the code with javap -v FILE | grep " = Class " . Check if you can find any duplicates.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      You will see that StringBuilder and Duplicates classes are mentioned twice.
      ACTUAL -
          #2 = Class #22 // java/lang/StringBuilder
          #7 = Class #26 // Duplicates
          #8 = Class #27 // java/lang/Object
        #16 = Class #22 // java/lang/StringBuilder
        #17 = Class #26 // Duplicates
        #18 = Class #28 // java/lang/String

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Duplicates {
          String concat(String s1, String s2) {
            return s1 + (s2 == s1 ? " " : s2);
          }
      }
      ---------- END SOURCE ----------

            pgovereau Paul Govereau (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: