]> source.dussan.org Git - javassist.git/commitdiff
fixed JASSIST-242
authorchibash <chiba@javassist.org>
Thu, 28 May 2015 00:41:41 +0000 (09:41 +0900)
committerchibash <chiba@javassist.org>
Thu, 28 May 2015 00:41:41 +0000 (09:41 +0900)
Readme.html
src/main/javassist/compiler/MemberCodeGen.java
src/test/javassist/JvstTest5.java

index b280a740f36a3fd13f5a8f569d58eef2da4c0b9b..446edebdeaa5611cad38f6897ab0303ac28f8c67 100644 (file)
@@ -283,7 +283,7 @@ see javassist.Dump.
 
 <p>-version 3.20
 <ul>
-<li>JIRA JASSIST-241, 246.
+<li>JIRA JASSIST-241, 242, 246.
 </ul>
 </p>
 
index f799eea07e3dce00a306fa1019a27f951c2888d6..67031992cfa0e3bc280b9e5d8800c7b39a6f1b1b 100644 (file)
@@ -568,9 +568,6 @@ public class MemberCodeGen extends CodeGen {
         // generate code for evaluating arguments.
         atMethodArgs(args, types, dims, cnames);
 
-        // used by invokeinterface
-        int count = bytecode.getStackDepth() - stack + 1;
-
         if (found == null)
             found = resolver.lookupMethod(targetClass, thisClass, thisMethod,
                                           mname, types, dims, cnames);
@@ -587,12 +584,12 @@ public class MemberCodeGen extends CodeGen {
         }
 
         atMethodCallCore2(targetClass, mname, isStatic, isSpecial,
-                          aload0pos, count, found);
+                          aload0pos, found);
     }
 
     private void atMethodCallCore2(CtClass targetClass, String mname,
                                    boolean isStatic, boolean isSpecial,
-                                   int aload0pos, int count,
+                                   int aload0pos,
                                    MemberResolver.Method found)
         throws CompileError
     {
@@ -651,8 +648,10 @@ public class MemberCodeGen extends CodeGen {
                 || declClass.isInterface() != targetClass.isInterface())
                 declClass = targetClass;
 
-            if (declClass.isInterface())
-                bytecode.addInvokeinterface(declClass, mname, desc, count);
+            if (declClass.isInterface()) {
+                int nargs = Descriptor.paramSize(desc) + 1;
+                bytecode.addInvokeinterface(declClass, mname, desc, nargs);
+            }
             else
                 if (isStatic)
                     throw new CompileError(mname + " is not static");
index 097dcd4ddd697b7d501efa8c117775d9518cc9fa..fcbbbb9957836f8e1f518217dc9a4c6b27c1d7cd 100644 (file)
@@ -67,4 +67,28 @@ public class JvstTest5 extends JvstTestRoot {
         String src = "public void id() { get(); }";
         CtMethod make = CtNewMethod.make(src, ctClass);
     }
+
+    public void testJIRA242() throws Exception {
+        Boolean ss = new Boolean(2 > 3);
+        ClassPool cp = ClassPool.getDefault();
+        CtClass cc = cp.get("test5.JIRA242$Hello");
+        CtMethod m = cc.getDeclaredMethod("say");
+        m.insertBefore("{ System.out.println(\"Say Hello...\"); }");
+
+        StringBuilder sb = new StringBuilder();
+        sb.append("BOOL_SERIES = createBooleanSeriesStep();");
+        //Below code cause the issue
+        sb.append("BOOL_SERIES.setValue(3>=3);"); //lets comment this and run it will work 
+        // Below code snippets will work
+        // this cast into exact class and call the same function
+        sb.append("((test5.JIRA242$BooleanDataSeries)BOOL_SERIES).setValue(3>=3);");
+        // this code snippet will set exact boolean variable to the function.
+        sb.append("boolean var = 3>=3;");
+        sb.append("BOOL_SERIES.setValue(var);");
+
+        m.insertBefore(sb.toString());
+        cc.writeFile();
+        Object obj = make(cc.getName());
+        assertEquals(0, invoke(obj, "say"));
+    }
 }