diff options
author | chibash <chiba@javassist.org> | 2013-05-27 19:20:13 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2013-05-27 19:20:13 +0900 |
commit | 29a580826f0372878e786e8a60c2f69713db1ecc (patch) | |
tree | 81cddf7366de250bc477b6a22a665e395f5503dd | |
parent | 3358dc269352383eb5e9c186d24ff4a292eeb637 (diff) | |
download | javassist-29a580826f0372878e786e8a60c2f69713db1ecc.tar.gz javassist-29a580826f0372878e786e8a60c2f69713db1ecc.zip |
fixed JASSIST-195
-rw-r--r-- | Readme.html | 2 | ||||
-rw-r--r-- | src/main/javassist/bytecode/stackmap/MapMaker.java | 27 | ||||
-rw-r--r-- | src/test/javassist/JvstTest4.java | 12 |
3 files changed, 37 insertions, 4 deletions
diff --git a/Readme.html b/Readme.html index 2cc92bb9..f6936b0d 100644 --- a/Readme.html +++ b/Readme.html @@ -285,7 +285,7 @@ see javassist.Dump. <ul> <li>The source code repository has been moved to <a href="https://github.com/jboss-javassist/javassist">GitHub</a></li>. -<li>JIRA JASSIST-181, 183, 184, 189, 162, 185, 186, 190. +<li>JIRA JASSIST-181, 183, 184, 189, 162, 185, 186, 190, 199. </ul> <p>-version 3.17.1 on December 3, 2012 diff --git a/src/main/javassist/bytecode/stackmap/MapMaker.java b/src/main/javassist/bytecode/stackmap/MapMaker.java index e0aa5dac..16d3f294 100644 --- a/src/main/javassist/bytecode/stackmap/MapMaker.java +++ b/src/main/javassist/bytecode/stackmap/MapMaker.java @@ -162,6 +162,7 @@ public class MapMaker extends Tracer { throws BadBytecode { make(code, blocks[0]); + findDeadCatchers(code, blocks); try { fixTypes(code, blocks); } catch (NotFoundException e) { @@ -303,6 +304,32 @@ public class MapMaker extends Tracer { destTypes[i] = srcTypes[i]; } + // Phase 1.5 + + /* + * Javac may generate an exception handler that catches only an exception + * thrown within the handler itself. It is dead code. + */ + + private void findDeadCatchers(byte[] code, TypedBlock[] blocks) throws BadBytecode { + int len = blocks.length; + for (int i = 0; i < len; i++) { + TypedBlock block = blocks[i]; + if (block.localsTypes == null) { // if block is dead code + BasicBlock.Catch handler = block.toCatch; + while (handler != null) + if (handler.body == block) { + BasicBlock.Catch handler2 + = new BasicBlock.Catch(block, handler.typeIndex, null); + traceException(code, handler2); + break; + } + else + handler = handler.next; + } + } + } + // Phase 2 /* diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index fe1ab7e8..c7582c34 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -866,7 +866,13 @@ public class JvstTest4 extends JvstTestRoot { String s2 = field2.getAnnotation(test4.JIRA181.Condition2.class).toString(); assertEquals("@test4.JIRA181$Condition2(condition=test4.JIRA181<T>.B[].class)", s2); } -} - - + public void testJIRA195() throws Exception { + CtClass cc = sloader.get("test4.JIRA195"); + CtMethod mth = cc.getDeclaredMethod("test"); + mth.getMethodInfo().rebuildStackMap(cc.getClassPool()); + cc.writeFile(); + Object obj = make(cc.getName()); + assertEquals(4, invoke(obj, "run")); + } +} |