diff --git a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/util/TryListBuilder.java b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/util/TryListBuilder.java index eb70371e..9a4c8114 100644 --- a/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/util/TryListBuilder.java +++ b/brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/writer/util/TryListBuilder.java @@ -166,7 +166,6 @@ public class TryListBuilder String existingType = existingHandler.getExceptionType(); String newType = handler.getExceptionType(); - // Don't add it if we already have a handler of the same type if (existingType == null) { if (newType == null) { if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) { @@ -176,10 +175,9 @@ public class TryListBuilder return; } } else if (existingType.equals(newType)) { - if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) { - throw new InvalidTryException( - "Multiple overlapping catches for %s with different handlers", existingType); - } + // dalvik doesn't reject cases when there are multiple catches with the same exception + // but different handlers. In practice, the first handler "wins". Since the later + // handler will never be used, we don't add it. return; } } diff --git a/brut.apktool.smali/dexlib2/src/test/java/org/jf/dexlib2/writer/util/TryListBuilderTest.java b/brut.apktool.smali/dexlib2/src/test/java/org/jf/dexlib2/writer/util/TryListBuilderTest.java index 360b5840..b02a512c 100644 --- a/brut.apktool.smali/dexlib2/src/test/java/org/jf/dexlib2/writer/util/TryListBuilderTest.java +++ b/brut.apktool.smali/dexlib2/src/test/java/org/jf/dexlib2/writer/util/TryListBuilderTest.java @@ -449,12 +449,8 @@ public class TryListBuilderTest { TryListBuilder tlb = new TryListBuilder(); tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5)); - try { - tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException1;", 6)); - } catch (TryListBuilder.InvalidTryException ex) { - return; - } - Assert.fail(); + tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException1;", 6)); + // no exception should be thrown... } @Test