aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorShigeru Chiba <chibash@users.noreply.github.com>2023-12-10 00:48:42 +0900
committerGitHub <noreply@github.com>2023-12-10 00:48:42 +0900
commitcbb59bda5d7a2252d0fff5aeeb42d1f1c699e021 (patch)
treeb0f36e53b20afaf28d02e673f8ad617fb9e21f42 /src/main
parent310fb8fe71b1d6950ac35219358dda6ffcacc69f (diff)
parente4470716576eaa37cc979c4345c7af33ec987aa7 (diff)
downloadjavassist-cbb59bda5d7a2252d0fff5aeeb42d1f1c699e021.tar.gz
javassist-cbb59bda5d7a2252d0fff5aeeb42d1f1c699e021.zip
Merge pull request #448 from catsalty/patch-2
Fix issue in no-standard [new] instruction replace
Diffstat (limited to 'src/main')
-rw-r--r--src/main/javassist/expr/NewExpr.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main/javassist/expr/NewExpr.java b/src/main/javassist/expr/NewExpr.java
index 3171fc3f..ee065167 100644
--- a/src/main/javassist/expr/NewExpr.java
+++ b/src/main/javassist/expr/NewExpr.java
@@ -193,6 +193,14 @@ public class NewExpr extends Expr {
*/
int codeSize = canReplace();
int end = pos + codeSize;
+ //check isStoreBeforeInit ,such as : new xx/xx ; dup;[astoreN];invokespecial xx/xx;
+ int beforeStoreOp = 0;
+ int preOp = iterator.byteAt(currentPos - 1);
+ if (iterator.byteAt(newPos + 3) == Opcode.DUP
+ && (preOp >= Opcode.ASTORE_0
+ && preOp <= Opcode.ASTORE_3) && currentPos - newPos == 5) {
+ beforeStoreOp = preOp;
+ }
for (int i = pos; i < end; ++i)
iterator.writeByte(NOP, i);
@@ -230,7 +238,12 @@ public class NewExpr extends Expr {
if (codeSize > 3) // if the original code includes DUP.
bytecode.addAload(retVar);
- replace0(pos, bytecode, bytecodeSize);
+ if (beforeStoreOp >= Opcode.ASTORE_0) {
+ bytecode.addOpcode(beforeStoreOp);
+ replace0(pos - 1, bytecode, bytecodeSize + 1);
+ } else {
+ replace0(pos, bytecode, bytecodeSize);
+ }
}
catch (CompileError e) { throw new CannotCompileException(e); }
catch (NotFoundException e) { throw new CannotCompileException(e); }