Skip to content

Commit bde266f

Browse files
committed
Merge branch '318009-fix-analyzer-regression' into 'master'
ASM Analyzer: fix regression introduced in fix of bug #317991. Closes #318009 See merge request asm/asm!388
2 parents d36a3db + c3f9957 commit bde266f

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

asm-analysis/src/main/java/org/objectweb/asm/tree/analysis/Analyzer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public Frame<V>[] analyze(final String owner, final MethodNode method) throws An
123123
TryCatchBlockNode tryCatchBlock = method.tryCatchBlocks.get(i);
124124
int startIndex = insnList.indexOf(tryCatchBlock.start);
125125
int endIndex = insnList.indexOf(tryCatchBlock.end);
126-
for (int j = startIndex; j <= endIndex; ++j) {
126+
for (int j = startIndex; j < endIndex; ++j) {
127127
List<TryCatchBlockNode> insnHandlers = handlers[j];
128128
if (insnHandlers == null) {
129129
insnHandlers = new ArrayList<>();
@@ -263,9 +263,18 @@ public Frame<V>[] analyze(final String owner, final MethodNode method) throws An
263263
catchType = Type.getObjectType(tryCatchBlock.type);
264264
}
265265
if (newControlFlowExceptionEdge(insnIndex, tryCatchBlock)) {
266+
// Merge the frame *before* this instruction, with its stack cleared and an exception
267+
// pushed, with the handler's frame.
266268
Frame<V> handler = newFrame(oldFrame);
269+
V exceptionValue = interpreter.newExceptionValue(tryCatchBlock, handler, catchType);
267270
handler.clearStack();
268-
handler.push(interpreter.newExceptionValue(tryCatchBlock, handler, catchType));
271+
handler.push(exceptionValue);
272+
merge(insnList.indexOf(tryCatchBlock.handler), handler, subroutine);
273+
// Merge the frame *after* this instruction, with its stack cleared and an exception
274+
// pushed, with the handler's frame.
275+
handler = newFrame(currentFrame);
276+
handler.clearStack();
277+
handler.push(exceptionValue);
269278
merge(insnList.indexOf(tryCatchBlock.handler), handler, subroutine);
270279
}
271280
}

asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/AnalyzerWithBasicVerifierTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,52 @@ void testAnalyze_invalidMultianewarray() {
247247
assertEquals("Error at instruction 2: Expected I, but found F", message);
248248
}
249249

250+
@Test
251+
void testAnalyze_validMethodWithExceptionHandlers() {
252+
Label label0 = new Label();
253+
Label label1 = new Label();
254+
Label label2 = new Label();
255+
Label label3 = new Label();
256+
Label label4 = new Label();
257+
Label label5 = new Label();
258+
Label label6 = new Label();
259+
MethodNode methodNode =
260+
new MethodNodeBuilder("(Ljava/lang/Object;)V", 3, 3)
261+
.trycatch(label0, label1, label2, "java/lang/Exception")
262+
.trycatch(label1, label3, label4, null)
263+
.trycatch(label5, label6, label4, null)
264+
.trycatch(label6, label2, label2, "java/lang/Exception")
265+
.aload(0)
266+
.ifnonnull(label0)
267+
.aconst_null()
268+
.athrow()
269+
.label(label0)
270+
.aload(0)
271+
.astore(2)
272+
.label(label1)
273+
.nop()
274+
.aload(2)
275+
.pop()
276+
.label(label3)
277+
.vreturn()
278+
.label(label4)
279+
.astore(1)
280+
.label(label5)
281+
.aload(2)
282+
.pop()
283+
.label(label6)
284+
.aload(1)
285+
.athrow()
286+
.label(label2)
287+
.astore(1)
288+
.go(label3)
289+
.build();
290+
291+
Executable analyze = () -> newAnalyzer().analyze(CLASS_NAME, methodNode);
292+
293+
assertDoesNotThrow(analyze);
294+
}
295+
250296
/**
251297
* Tests that the precompiled classes can be successfully analyzed with a BasicVerifier.
252298
*

0 commit comments

Comments
 (0)