0

I have some class files that I have been decompiling, but I have found that the <>s next to my Sets, Lists, Iterators, etc. are not being shown in the output.

I have tried CFR, Procyon, JD-GUI, and FernFlower.

Upon attempting to recompile those classes, the compiler fails to do so mentioning a problem with the fact that my <>s are missing.

UPDATE: The <>s are shown in a Java 7 decompiled file, but not in a Java 6 one, as shown below:

The class in Java 7: Class in Java 7

The class in Java 6: Class in Java 6

Does anyone know why I might not be getting the <>s in the output?

Sameer Puri
  • 908
  • 7
  • 20
  • 1
    possible duplicate of [Java generics - type erasure - when and what happens](http://stackoverflow.com/questions/339699/java-generics-type-erasure-when-and-what-happens) – Todd Jan 20 '15 at 02:28
  • 1
    Wait...it is not a duplicate. The <>s are retrieved by JD-GUI in Java 7 but not in Java 6 – Sameer Puri Jan 20 '15 at 02:30
  • `>` would be incorrect and result in compile-time errors. Maybe `` might work. – Thilo Jan 20 '15 at 02:33
  • Yes, I have attached pictures from JD-GUI of the class I had that was compiled in Java 6. I decompiled it, added the types, and recompiled it in Java 7; that is the first picture. – Sameer Puri Jan 20 '15 at 02:37
  • I'm guessing that the Java 7 javac was changed to add more annotations to the .class file. One could, if they were really interested, dump equivalent 6 and 7 files and look for the difference. – Hot Licks Jan 20 '15 at 02:40
  • @HotLicks: I doubt it. You could have annotations on public fields from the very beginning (Java5). http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Field.html#getGenericType%28%29 (since 1.5) – Thilo Jan 20 '15 at 02:42
  • @HotLicks: I am crossing my fingers that is not the case...it will be interesting to see what happens after I use krakatau... – Sameer Puri Jan 20 '15 at 02:43
  • Ok I tried and failed, looks like HotLicks is probably right – Sameer Puri Jan 20 '15 at 02:50
  • Anyone have any other clues as to what this might be? If it was just type erasure, I'm pretty sure JD-GUI would be incapable of reconstructing the <>s in a Java 7 class like it did. What is also interesting, as noted by @Thilo, is that it doesn't preserve it on the right side. I'm clueless here, so any ideas will be greatly appreciated – Sameer Puri Jan 20 '15 at 03:04
  • Why doesn't someone dump the files to find out? – Hot Licks Jan 20 '15 at 03:34
  • [Mekanism is open source.](https://github.com/aidancbrady/Mekanism) Decompiling it is probably a waste of time. – user253751 Jan 20 '15 at 03:52
  • I'm already aware of that @immibis, it is a version from Voltz :( By the way I like your microblocks mod – Sameer Puri Jan 20 '15 at 15:38
  • @HotLicks just did, the interesting thing is that jdk7 and jdk6 both return no <>s, but I find that the compiler I used in the first picture does...I'll get back to you on this – Sameer Puri Jan 20 '15 at 15:41

2 Answers2

0

You aren't getting the <>(s) because of Type-Erasure the first step of which is

Replace all type parameters in generic types with their bounds or Object if the type parameters are unbounded. The produced bytecode, therefore, contains only ordinary classes, interfaces, and methods.

Elliott Frisch
  • 183,598
  • 16
  • 131
  • 226
0

That looks like a bug in the decompiler. Are you using the same version of it in both cases?

For public fields (just like methods) the type annotations are preserved (because they are required to compile against the class).

But note that the annotation is not preserved on the right side of the assignment (because that is not part of the class signature).

Thilo
  • 241,635
  • 91
  • 474
  • 626
  • So...if I were to edit the .class file and, say change the major/minor version from 50 to 51, do you think they would show? – Sameer Puri Jan 20 '15 at 02:39
  • No, this must work with even Java 5. Is it the same version of your decompiler stack for both cases (only difference the JDK version)? – Thilo Jan 20 '15 at 02:40
  • I.E: krakatau -d MYCLASS.class -o . nano MYCLASS.j and change 50 to 51 krakatau -a MYCLASS.j -o . ? – Sameer Puri Jan 20 '15 at 02:40