Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java class method stubs with /* compiled code */

I just received a third party authentication library to use in my clients application. I didn't receive any documentation with it and am trying to dig through the source and see how it works. I'm very to new Java when i click Go To -> Declaration on methods in IntelliJ it sends me to a .class file and i see a bunch of stubbed methods with /* compiled code */ in the methods.

I'm fairly sure this is common in Java i just don't know what to search for to learn about what exactly is going on. Any clarification would be great.

like image 852
David Avatar asked Aug 26 '13 13:08

David


People also ask

What is decompiled .class file?

A Java Decompiler is a special type of decompiler which takes a class file as input and produces Java source code as output. The decompilation is exactly the reverse process of compilation. Thus, decompiler does not produce a replica of the source code.

How do I change a read only class in IntelliJ?

Toggle read-only attribute of a fileFrom the main menu, select File | File Properties | Make File Read-only or File | File Properties | Make File Writable.

How do I view .class files in IntelliJ?

Open the necessary . class file in the editor in IntelliJ IDEA and then select View | Show Bytecode from the main menu. If you're not seeing this option, make sure that the bundled Bytecode Viewer plugin is enabled.


2 Answers

This typically meant that you don't have the source code, and IntelliJ IDEA would just display /* compiled code */ as a placeholder for the source code you don't have. I believe this has now changed, and IntelliJ comes bundled with a full Java decompiler plugin, and will display the decompiled source code as standard.

To better see what's going on, the best would be to receive the actual source code of the third party library.

You should of course also get the documentation, as reading the source code and guessing how to use a library usually isn't the best way to learn.

The second best option would be use the decompiler plugin in IntelliJ, that will automatically decompile the Java class file (note that the license for your third party library may disallow you to do just that). This will never be a 100% solution, but in most cases it's better than nothing.

like image 129
Harald K Avatar answered Nov 22 '22 10:11

Harald K


You should really search/ask for documentation. Javadoc usually is invaluable if the method does stuff you can't guess from its name. Otherwise use a decompiler such as JD-GUI.

.java sourcecode is compiled to .class bytecode by compilers such as javac. The compiler may optimise specific things, and a compilation-decompilation process if highly unlikely to yield the same source. Also, all comments should be deleted and if the code wasn't compiled in debug mode, even the variable names are lost. So: Decompilation is not a good alternative to handcrafted documentation.

like image 29
tilpner Avatar answered Nov 22 '22 09:11

tilpner