Browse Source

fixed JASSIST-242

tags/rel_3_20_0_ga
chibash 9 years ago
parent
commit
a4f46cd3a9
3 changed files with 31 additions and 8 deletions
  1. 1
    1
      Readme.html
  2. 6
    7
      src/main/javassist/compiler/MemberCodeGen.java
  3. 24
    0
      src/test/javassist/JvstTest5.java

+ 1
- 1
Readme.html View File



<p>-version 3.20 <p>-version 3.20
<ul> <ul>
<li>JIRA JASSIST-241, 246.
<li>JIRA JASSIST-241, 242, 246.
</ul> </ul>
</p> </p>



+ 6
- 7
src/main/javassist/compiler/MemberCodeGen.java View File

// generate code for evaluating arguments. // generate code for evaluating arguments.
atMethodArgs(args, types, dims, cnames); atMethodArgs(args, types, dims, cnames);


// used by invokeinterface
int count = bytecode.getStackDepth() - stack + 1;

if (found == null) if (found == null)
found = resolver.lookupMethod(targetClass, thisClass, thisMethod, found = resolver.lookupMethod(targetClass, thisClass, thisMethod,
mname, types, dims, cnames); mname, types, dims, cnames);
} }


atMethodCallCore2(targetClass, mname, isStatic, isSpecial, atMethodCallCore2(targetClass, mname, isStatic, isSpecial,
aload0pos, count, found);
aload0pos, found);
} }


private void atMethodCallCore2(CtClass targetClass, String mname, private void atMethodCallCore2(CtClass targetClass, String mname,
boolean isStatic, boolean isSpecial, boolean isStatic, boolean isSpecial,
int aload0pos, int count,
int aload0pos,
MemberResolver.Method found) MemberResolver.Method found)
throws CompileError throws CompileError
{ {
|| declClass.isInterface() != targetClass.isInterface()) || declClass.isInterface() != targetClass.isInterface())
declClass = targetClass; 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 else
if (isStatic) if (isStatic)
throw new CompileError(mname + " is not static"); throw new CompileError(mname + " is not static");

+ 24
- 0
src/test/javassist/JvstTest5.java View File

String src = "public void id() { get(); }"; String src = "public void id() { get(); }";
CtMethod make = CtNewMethod.make(src, ctClass); 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"));
}
} }

Loading…
Cancel
Save