Marcus Junius Brutus
Marcus Junius Brutus

Reputation: 27286

How to compare class files

Are there any tools to compare .class files at a semantic level? At the very least I want to see method signature changes (e.g. the sort of information I could get by comparing the javap outputs) but also logic (bytecode) changes inside the methods themselves even when the API is not changed. The tool should be clever enough to not report false alarms e.g. in the case of whole methods changing place and being moved up or down within the same source file.

Upvotes: 1

Views: 2733

Answers (1)

Marcus Junius Brutus
Marcus Junius Brutus

Reputation: 27286

I ended up using the following bash script (which only checks signatures however). I 'm sure it can be improved as at the moment fails to keep the signatures close to the methods themselves due to the sorting operation.

#!/usr/bin/env bash
if [ $# -ne 2 ]
then
    echo "usage is $0 <class A> <class B>"
else
    diff <(javap -s "$1" | sort | grep -v ^$) <(javap -s "$2" | sort | grep -v ^$)
fi

Upvotes: 2

Related Questions