From 8b08ac380670ea296df7360afa5f2d88c0cdcdcb Mon Sep 17 00:00:00 2001 From: Skylot <118523+skylot@users.noreply.github.com> Date: Tue, 27 May 2025 19:49:57 +0100 Subject: [PATCH] fix: wrap `MethodThrowsVisitor` insns processing in try/catch (#2441) --- .../dex/visitors/MethodThrowsVisitor.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/MethodThrowsVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/MethodThrowsVisitor.java index 1cc8e6404..72b8cb4ac 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/MethodThrowsVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/MethodThrowsVisitor.java @@ -110,27 +110,30 @@ public class MethodThrowsVisitor extends AbstractVisitor { toRemove.forEach(excSet::remove); } - private void processInstructions(MethodNode mth) throws JadxException { + private void processInstructions(MethodNode mth) { if (mth.isNoCode() || mth.getBasicBlocks() == null) { return; } - - blocks: for (final BlockNode block : mth.getBasicBlocks()) { - // Skip e.g. throw instructions of synchronized regions - boolean skipExceptions = block.contains(AFlag.REMOVE) || block.contains(AFlag.DONT_GENERATE); - Set excludedExceptions = new HashSet<>(); - CatchAttr catchAttr = block.get(AType.EXC_CATCH); - if (catchAttr != null) { - for (ExceptionHandler handler : catchAttr.getHandlers()) { - if (handler.isCatchAll()) { - continue blocks; + try { + blocks: for (final BlockNode block : mth.getBasicBlocks()) { + // Skip e.g. throw instructions of synchronized regions + boolean skipExceptions = block.contains(AFlag.REMOVE) || block.contains(AFlag.DONT_GENERATE); + Set excludedExceptions = new HashSet<>(); + CatchAttr catchAttr = block.get(AType.EXC_CATCH); + if (catchAttr != null) { + for (ExceptionHandler handler : catchAttr.getHandlers()) { + if (handler.isCatchAll()) { + continue blocks; + } + excludedExceptions.add(handler.getArgType().toString()); } - excludedExceptions.add(handler.getArgType().toString()); + } + for (final InsnNode insn : block.getInstructions()) { + checkInsn(mth, insn, excludedExceptions, skipExceptions); } } - for (final InsnNode insn : block.getInstructions()) { - checkInsn(mth, insn, excludedExceptions, skipExceptions); - } + } catch (Exception e) { + mth.addWarnComment("Failed to analyze thrown exceptions", e); } }