Skip to content

Commit

Permalink
fixes the bug reported in Issue #241.
Browse files Browse the repository at this point in the history
It makes $r available in the code given to CtBehavior#insertBefore().
  • Loading branch information
chibash committed Jan 27, 2019
1 parent 576b141 commit 6ea8021
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Readme.html
Expand Up @@ -283,7 +283,7 @@ <h2>Changes</h2>

<p>-version 3.25
<ul>
<li>GitHub Issue #72 (PR #231), #242 (PR #243).
<li>GitHub Issue #72 (PR #231), #241, #242 (PR #243).
</ul>

<p>-version 3.24.1 on December 9, 2018
Expand Down
Binary file modified javassist.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/javassist/CtBehavior.java
Expand Up @@ -782,7 +782,7 @@ private void insertBefore(String src, boolean rebuild)
Modifier.isStatic(getModifiers()));
jv.recordParamNames(ca, nvars);
jv.recordLocalVariables(ca, 0);
jv.recordType(getReturnType0());
jv.recordReturnType(getReturnType0(), false);
jv.compileStmnt(src);
Bytecode b = jv.getBytecode();
int stack = b.getMaxStack();
Expand Down
14 changes: 14 additions & 0 deletions src/test/javassist/JvstTest5.java
Expand Up @@ -484,4 +484,18 @@ public void testSwitchCaseWithStringConstant2() throws Exception {
Object obj = make(cc.getName());
assertEquals(1, invoke(obj, "run"));
}

// Issue #241
public void testInsertBeforeAndDollarR() throws Exception {
CtClass cc = sloader.get(test5.InsertBeforeDollarR.class.getName());
CtMethod m = cc.getDeclaredMethod("foo");
m.insertBefore("{ if ($1 == 1) return ($r)$2; }");
try {
m.insertBefore("{ $_ = \"bar\"; }");
assertTrue(false);
} catch (CannotCompileException e) {}
cc.writeFile();
Object obj = make(cc.getName());
assertEquals(1, invoke(obj, "run"));
}
}
14 changes: 14 additions & 0 deletions src/test/test5/InsertBeforeDollarR.java
@@ -0,0 +1,14 @@
package test5;

public class InsertBeforeDollarR {
public int run() {
if (foo(1, "baz").equals("baz"))
return 1;
else
return 0;
}

public String foo(int i, Object obj) {
return String.valueOf(i);
}
}

0 comments on commit 6ea8021

Please sign in to comment.