-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing unused ExcHandlers blocks #2086
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just small requests to improve code.
Also, please add simple Smali test (just copy whole method, also add disableCompilation()
, code will not compile because of external classes).
jadx-core/src/main/java/jadx/core/dex/visitors/blocks/BlockExceptionHandler.java
Show resolved
Hide resolved
jadx-core/src/main/java/jadx/core/dex/visitors/blocks/BlockProcessor.java
Outdated
Show resolved
Hide resolved
Here is a minimized standalone example for this issue that could be used for a unit test. Steps to reproduce: compile with openjdk8, "use dx/d8 to convert java bytecode" [x], "Plugins > Java convert > convert mode": "d8" With convert mode "dx" there is still a NPE. import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class UnusedExceptionHandlers1 implements AutoCloseable {
public static void doSomething(final Object unused1, final Object[] array, final Object o1,
final Object o2, final Object unused2) {
for (final Object item : array) {
ByteBuffer buffer = null;
try (final UnusedExceptionHandlers1 u = doSomething2(o1, "", o2)) {
try (final FileInputStream fis = new FileInputStream(u.getFilename())) {
final FileChannel fileChannel = fis.getChannel();
buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 42);
} catch (final IOException e) {
// ignore
}
} catch (final IOException e) {
// ignore
}
}
}
private String getFilename() {
return null;
}
private static UnusedExceptionHandlers1 doSomething2(final Object o1, final String s,
final Object o2) {
return null;
}
@Override
public void close() throws IOException {}
} |
Ok, I will add this test also. |
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch2.java
Outdated
Show resolved
Hide resolved
…reachableCatch2.java
@Away-pp great! Thank you for your work 👍 |
Removing unused ExcHandlers blocks in order to fix some decompilation errors caused by Unreachable blocks.
The root of this problem (for the current fix) is that some
try
s may never actually throw an exception.Therefore the related
catch
may become unreachable.The solution is that at the end of the try/catch processing, to look for unreachable blocks from the exception handlers.
An example of method that was not decompiled before:
Original code
https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/android/provider/FontsContract.java;l=726?q=prepareFontData
Decompiled code