How can it be verified that a Java file and its associated class file have the same code?

Viewed 88

I'm working on a legacy application that was built nearly 20 years ago, and many of the class files in production contain code that was never committed in Java files. Due to which we can not build its war and compile it as a complete project. Now, whenever we need to change something, we have to compile java files one by one and place those class files one by one on production because the project cannot be compiled as a whole as the local java files does not contain all the code and give compilation. Is there a tool or technique I can use to check if a java file and its corresponding class file are synced and have the same code? Because if they are not same I need to find the delta between java and its corresponding class file on production.

1 Answers

I doubt there is a way to prove Java source and class files have the same code. Depending on the compilers and configuration used, the same Java code can result in different class files. Just think of compiling with or without debug information.

What might work better is to have one secure pipeline that is intended to grab code from version control and produce signed class files. Part of the signature should be the status/tag/commit from version control that was used to create the release.

In production you would just have to verify the signature is still valid (the files have not been tampered with), then backtrack in version control which code was used exactly.

Edit: Since you edited your question... Going towards your situation, I'd probably put all the code into version control. Classes where you have the source go in as source, those where the source is missing go in as class files.

Your build process would compile what is possible, merge in the existing class files and produce builds as I described above. Over time, when you decompile more classes and work on it to have suitable code, add it to version control while removing the corresponding class files.

Related