Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is any information lost when compiling to a .class and decompiling back?

I think java should be fairly friendly to decompilation, that is, the .class files themselves have quite a lot of data that still resembles the original source fairly well.

Would it be possible to construct the original source from a decompiled .class file, that would be completely equivalent, or are there any java constructs that get transformed during the process?

For example, I could see syntactic sugar like enhanced for loop causing problems.

Would I be able to repeat the process several times and still arrive at where I started from?

like image 749
Zavior Avatar asked Mar 17 '23 01:03

Zavior


1 Answers

The simple answer is that yes, information is lost.

Comments, in particular, are always lost. Whether original variable names are lost depends on the compiler options when the code was compiled. Code compiled with the debug options (-g) will be more readable when decompiled.

When you decompile, you get source code that is functionally equivalent, but not exactly the same as the source that when in.

like image 119
Rand Avatar answered Mar 29 '23 23:03

Rand