-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove unused ExcHandlers blocks (PR #2086)
* Removing unused ExcHandlers blocks * Improving removing unused ExcHandlers blocks * Removing gradlew of the commit * Adding test 2 for UnreachableCatch * Update jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch2.java --------- Co-authored-by: Away-pp <vladimir@DESKTOP-KESF23K> Co-authored-by: skylot <[email protected]>
- Loading branch information
1 parent
7e628ad
commit 276ee53
Showing
5 changed files
with
481 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package jadx.tests.integration.trycatch; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.SmaliTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
@SuppressWarnings("CommentedOutCode") | ||
public class TestUnreachableCatch extends SmaliTest { | ||
|
||
// @formatter:off | ||
/* | ||
private static Map<Uri, ByteBuffer> prepareFontData(Context context, FontInfo[] fonts, | ||
CancellationSignal cancellationSignal) { | ||
final HashMap<Uri, ByteBuffer> out = new HashMap<>(); | ||
final ContentResolver resolver = context.getContentResolver(); | ||
for (FontInfo font : fonts) { | ||
if (font.getResultCode() != Columns.RESULT_CODE_OK) { | ||
continue; | ||
} | ||
final Uri uri = font.getUri(); | ||
if (out.containsKey(uri)) { | ||
continue; | ||
} | ||
ByteBuffer buffer = null; | ||
try (final ParcelFileDescriptor pfd = | ||
resolver.openFileDescriptor(uri, "r", cancellationSignal)) { | ||
if (pfd != null) { | ||
try (final FileInputStream fis = | ||
new FileInputStream(pfd.getFileDescriptor())) { | ||
final FileChannel fileChannel = fis.getChannel(); | ||
final long size = fileChannel.size(); | ||
buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, size); | ||
} catch (IOException e) { | ||
// ignore | ||
} | ||
} | ||
} catch (IOException e) { | ||
// ignore | ||
} | ||
// TODO: try other approach?, e.g. read all contents instead of mmap. | ||
out.put(uri, buffer); | ||
} | ||
return Collections.unmodifiableMap(out); | ||
} | ||
*/ | ||
// @formatter:on | ||
|
||
@Test | ||
public void test() { | ||
disableCompilation(); | ||
allowWarnInCode(); | ||
|
||
ClassNode cls = getClassNodeFromSmali(); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsString("IOException")); | ||
assertThat(code, containsString("Collections.unmodifiableMap")); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package jadx.tests.integration.trycatch; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.FileChannel; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.SmaliTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
@SuppressWarnings("CommentedOutCode") | ||
public class TestUnreachableCatch2 extends SmaliTest { | ||
|
||
public static 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 { | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
// TODO: result code not compilable because of 'break' after 'throw' | ||
disableCompilation(); | ||
String code = getClassNode(UnusedExceptionHandlers1.class).getCode().toString(); | ||
assertThat(code, containsString("IOException")); | ||
} | ||
} |
Oops, something went wrong.