1

I inherited a java project but have a been given a few version of the source code, and am not sure witch one is the live version.

Is there a way to compare the source code to the class files to see which one matches?

PS. how does the intelij debugger know if there is a source mismatch? Can i run that test globally on all the class files?

8
  • 3
    I don't know how to answer your question. When you figure it out be sure to use version control, such as Git, so that you don't have this problem again in the future. Commented May 17, 2018 at 9:44
  • I remember java complaining of source/class file version mismatch in case of our model classes being out of date on the client. So it has to store some kind of version information in .class I guess.. Commented May 17, 2018 at 9:45
  • match the dates of all the version of the source code with the live version release date Commented May 17, 2018 at 9:46
  • 2
    I'd try to compile the source, then decompile all .class files, then check for diffs Commented May 17, 2018 at 9:46
  • 2
    Compile the source code and then compare the .classes Commented May 17, 2018 at 9:46

1 Answer 1

1

There is javap to disassemble class files to text. With many options to show the methods' instructions and such. Compiling the source code with the same compiler should give similar java bytecode sources.

Sign up to request clarification or add additional context in comments.

3 Comments

can you share some examples of same?
Is there a way to get the original compile options from the class files? Is the version of javac important?
The java version can be taken from the major/minor version: major - 44 = the java version, 52 would be java 8. Then debugging info can be ommitted, line numbers only, with local names. And so on. Hand work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.