Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue in no-standard [new] instruction replace #448

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main/javassist/expr/NewExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ public void replace(String statement) throws CannotCompileException {
*/
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);

Expand Down Expand Up @@ -230,7 +238,12 @@ public void replace(String statement) throws CannotCompileException {
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); }
Expand Down