Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What settings affect the layout of compiled java .class files? How can you tell if two compiled classes are equal?

I have an app that was compiled with the built-in Eclipse "Compile" task. Then I decided to move the build procedure into Ant's javac, and the result ended being smaller files.

Later I discovered that adjusting the debuglevel to "vars,lines,source" I could embed the same debug information that Eclipse did, and in a lot of cases files stayed exactly the same size but the internal layout was different. And as a consequence, I couldn't use md5sum signatures to determine if they were exactly the same version.

Besides debug information, what can be the reason that 2 supposedly equal files get a different internal layout or size?

And how can you compare compiled .class files?

like image 216
Camilo Díaz Repka Avatar asked Dec 31 '22 03:12

Camilo Díaz Repka


1 Answers

THere is no required order for things such as the order of the constant pool entries (essentially all of the symbol info) as well as the attributes for each field/method/class. Different compilers are free to write out in whatever order they want.

You can compared compiled classes, but you would need to dig into the class file structure and parse it. There are libraries out there for doing that, like BCEL or ASM, but I am not 100% sure they will help you with what you want to do.

like image 67
TofuBeer Avatar answered Jan 07 '23 12:01

TofuBeer