Reputation:
I'm new to Java and I'm trying to understand something. I managed to get a .jar file for a local device to communicate with my laptop. It works fine, but I would like to do an upgrade and scoop around the codes and change some details. I used a Java Decompiler on the .jar file and managed to take a look at the class files. However, whenever I decompile them into source codes, errors will occur in my IDE, and I'm unable to build them. What exactly happened? If it's working fine in the .jar why does it produce errors?
Upvotes: 1
Views: 4283
Reputation: 130
Completely agree with Antimony. There is no decompiler which decompiles always without any error. Sometimes it decompiles well, sometimes not.
The best way is to have several decompilers and use them each by other to decrease errors in decompiled source.
If you use Eclipse I would suggest https://marketplace.eclipse.org/content/enhanced-class-decompiler
If you use IntelliJ try this decompiler Jar Explorer.
Upvotes: 0
Reputation: 39451
Compilation is a lossy process, so decompilation is always a "best effort" endeavor. Java bytecode is unusually high level, so Java decompilation is relatively easy compared to other languages, but it will still never be 100% complete. Therefore, you should not be surprised to see errors when re-compiling decompiled source.
If you want to work directly with bytecode, I would recommend using the Krakatau disassembler and assembler. Instead of decompiling to Java source, the disassembler converts bytecode into a human readable assembly format which is specifically designed to be converted to and from bytecode losslessly. However, it requires a good understanding of low level Java bytecode to use.
Upvotes: 1