I am trying to make a compatibility class loader.
General scenario. People edit the source file, change the contents of a few methods and add a few fields and then recompile the class.
I then compare the original class and the changed class with javassist.
I need to detect when the methods haven't been changed. I can get the two CtMethods and I tried measuring the length of the code attribute (basemethod.getMethodInfo().getCodeAttribute().getCode() != other) but that fails when the change is a single field access redirection for example. I also tried comparing the contents of the arrays but that didn't work as various bytes at seemingly coordinated locations in the attribute have different values. Due to the fact I don't actually understand how to read the bytecode I'm unable to work out a solution.
If someone could help point me in the right direction or give me a sample of code that could analyse this for me that would be great.
Thankyou for your time.
I think you would have to use a CodeIterator to go over the code one instruction at a time and compare them. You need to make sure that the instructions are the same, and also that the value of any items that they point to in the const pool is also the same. A complete list of the bytecode instructions can be found at:
|Retrieving data ...|