You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made some tests with casts and would like to report some compilation issues (missing casts) and a little feature request (avoid intermediate or unnecessary casts). My tests were made with openjdk8, latest git version, java-input and java-convert (same results):
publicclassJadxCastTest {
publicvoidtestCasts() {
testShort((short)0); // compilation issue, cast missing after decompilationtestShort((short)getInt()); // oktestByte((byte)0); // oktestByte((byte)getInt()); // oktestChar((char)0); // compilation issue, cast missing after decompilationtestChar((char)getInt()); // oktestShort((short)0L); // compilation issue, cast missing after decompilationtestShort((short)getLong()); // ok, but no intermediate cast to int necessarytestByte((byte)0L); // const becomes an inttestByte((byte)getLong()); // ok, but no intermediate cast to int necessarytestChar((char)0L); // compilation issue, cast missing after decompilation, const becomes an inttestChar((char)getLong()); // ok, but no intermediate cast to int necessarytestShort((short)' '); // compilation issue, cast missing after decompilation, const becomes an inttestShort((short)getChar()); // oktestByte((byte)' '); // ok, but const becomes an inttestByte((byte)getChar()); // ok
}
privatelonggetLong() {
return1L; // const becomes an int
}
privatechargetChar() {
return' ';
}
privateintgetInt() {
return1;
}
privatevoidtestChar(charc) {
}
privatevoidtestByte(byteb) {
}
privatevoidtestShort(shorts) {
}
}
I observed that jadx converts long and char constants to int. I don't see a problem here as long as the results are the same. But I think cascading casts (long -> int -> short) could be optimized.
This sample can be used for unit tests.
The text was updated successfully, but these errors were encountered:
@nitram84 I commit a fix for compilation issues and unnecessary cascading casts.
Although, I must note that type of some constants can't be restored during decompilation because java compiler can convert/cast constant at compile time, so in bytecode appear already converted ones, so jadx don't know original type.
In your sample, for example, this happens with char constants: bytecode load them as a byte, so char type info is lost completely.
I made some tests with casts and would like to report some compilation issues (missing casts) and a little feature request (avoid intermediate or unnecessary casts). My tests were made with openjdk8, latest git version, java-input and java-convert (same results):
I observed that jadx converts long and char constants to int. I don't see a problem here as long as the results are the same. But I think cascading casts (long -> int -> short) could be optimized.
This sample can be used for unit tests.
The text was updated successfully, but these errors were encountered: