I have decompiled a class with javap
and I'm seeing some duplicates in the Constant Pool section, like this:
#19 = Class #350 // java/lang/StringBuilder
... Some other class constants here
#318 = Class #350 // java/lang/StringBuilder
Methodrefs refer to only one of them:
#20 = Methodref #19.#351 // java/lang/StringBuilder."<init>":()V
#22 = Methodref #19.#353 // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
#24 = Methodref #19.#355 // java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
#25 = Methodref #19.#356 // java/lang/StringBuilder.toString:()Ljava/lang/String;
#110 = Methodref #19.#445 // java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
Is this class correct according to The class File Format? I thought that every Class is mentioned just once and referred later by it's index in the bytecode part.
$ javac -version
javac 1.7.0_15
An other strange thing is in the source of the class representing the Constant Pool in javac Pool.java. This states that it will not put an object into the the pool if it is already there (with a help of a HashMap). I wonder if the equals()/hashCode() methods of these classes are implmented correctly.