Skip to content

Commit

Permalink
Fix insertAuxInitializer may cause inconsistent stack height problem
Browse files Browse the repository at this point in the history
Usually, constructor only load super class's constructor's init params into stack.
After this() or super() called, stack will be empty. If so, we insertAuxInitializer
right after this() or super() can reuse max stack size if it enough.

But, there is some weird class out there, their constructors load all in-constructor
init field value into stack before this() or super() call. In this case,
after this() or super() call, stack is not empty, even maybe full.

In summary, insertAuxInitializer should increase MaxStack anyway.
  • Loading branch information
shifujun committed Dec 11, 2023
1 parent fbd20b1 commit 2cdc027
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/main/javassist/CtClassType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1763,8 +1763,7 @@ private static void insertAuxInitializer(CodeAttribute codeAttr,
int pos = it.insertEx(initializer.get());
it.insert(initializer.getExceptionTable(), pos);
int maxstack = codeAttr.getMaxStack();
if (maxstack < stacksize)
codeAttr.setMaxStack(stacksize);
codeAttr.setMaxStack(maxstack + stacksize);
}

private int makeFieldInitializer(Bytecode code, CtClass[] parameters)
Expand Down

0 comments on commit 2cdc027

Please sign in to comment.