I decompiled an APK file, then tried to compile it and received an "Unreachable statement" compiler error, I want to know is it a obfuscator trick, or decompiler failure? How is it possible? Used dex2jar and Java Decompiler
And here is the decompiled method
public void onSensorChanged(SensorEvent paramSensorEvent) {
float[] arrayOfFloat = paramSensorEvent.values;
switch (paramSensorEvent.sensor.getType())
{
}
do
{
return;
} while (this.aDegree == arrayOfFloat[0]);
this.aDegree = arrayOfFloat[0];
invalidate();
}
It's possible because unreachable statement
is a useful compile time error, not a runtime check/constraint.
The code that you decompiled might have had something like this originally:
boolean debug = true;
do {
if(debug) {
return;
}
}while (this.aDegree == arrayOfFloat[0]);
The compiler is smart enough to know that debug
is always true and doesn't bother with the check in the byte code (for efficiency).
Obviously my example is quite contrived, in reality it was probably more complex (although the end result is the same).