]> source.dussan.org Git - javassist.git/commitdiff
fixed JASSIST-195
authorchibash <chiba@javassist.org>
Mon, 27 May 2013 10:20:13 +0000 (19:20 +0900)
committerchibash <chiba@javassist.org>
Mon, 27 May 2013 10:20:13 +0000 (19:20 +0900)
Readme.html
src/main/javassist/bytecode/stackmap/MapMaker.java
src/test/javassist/JvstTest4.java

index 2cc92bb9bc6369634853ebd9c21b387b4e5e7a71..f6936b0dd5b5661afa8eb1bff3c9f2e5e804ca73 100644 (file)
@@ -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
index e0aa5dac0ba960b38c72d63c4b87749fe5c236ff..16d3f2945f54789f7c983ab420e7f909e48a7583 100644 (file)
@@ -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
 
     /*
index fe1ab7e8d1aefed2e79604fb253a64aa19ed28ea..c7582c34b7cecedd7b3afb86f5759415b00c3a07 100644 (file)
@@ -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"));        
+    }
+}