return;
}
StackState currentStackState = getStack();
StackState mergeStackState = stackFrame.getStackState();
if (currentStackState.size() != mergeStackState.size()) {
throw new InvalidBytecodeException("Cannot merge stack frames, different stack sizes");
}
for (int i = 0; i < mergeStackState.size(); ++i) {
StackEntry currentEntry = currentStackState.getContents().get(i);
StackEntry mergeEntry = mergeStackState.getContents().get(i);
if (mergeEntry.getType() == currentEntry.getType()) {
if (mergeEntry.getType() == StackEntryType.OBJECT) {
if (!mergeEntry.getDescriptor().equals(currentEntry.getDescriptor())) {
if (!mergeEntry.equals("Ljava/lang/Object;")) {
// we cannot reliably determine if closes common superclass at this point
// so we will just mark the stack map attribute as invalid
stackMapAttributeValid = false;
}
}
}
} else if (!((mergeEntry.getType() == StackEntryType.NULL && currentEntry.getType() == StackEntryType.OBJECT) || (mergeEntry
.getType() == StackEntryType.OBJECT && currentEntry.getType() == StackEntryType.NULL))) {
throw new InvalidBytecodeException("Cannot merge stack frame " + currentStackState + " with frame "
+ mergeStackState + " stack entry " + i + " is invalid");
}
}
LocalVariableState currentLocalVariableState = getLocalVars();
LocalVariableState mergeLocalVariableState = getLocalVars();
if (currentLocalVariableState.size() < mergeLocalVariableState.size()) {
throw new InvalidBytecodeException(
"Cannot merge stack frames, merge location has less locals than current location");
}
for (int i = 0; i < mergeLocalVariableState.size(); ++i) {
StackEntry currentEntry = currentLocalVariableState.getContents().get(i);
StackEntry mergeEntry = mergeLocalVariableState.getContents().get(i);
if (mergeEntry.getType() == currentEntry.getType()) {
if (mergeEntry.getType() == StackEntryType.OBJECT) {
if (!mergeEntry.getDescriptor().equals(currentEntry.getDescriptor())) {
if (!mergeEntry.equals("Ljava/lang/Object;")) {
// we cannot reliably determine if closes common superclass at this point
// so we will just mark the stack map attribute as invalid
stackMapAttributeValid = false;
}
}
}
} else if (!((mergeEntry.getType() == StackEntryType.NULL && currentEntry.getType() == StackEntryType.OBJECT) || (mergeEntry
.getType() == StackEntryType.OBJECT && currentEntry.getType() == StackEntryType.NULL))) {
throw new InvalidBytecodeException("Cannot merge stack frame " + currentLocalVariableState + " with frame "
+ currentLocalVariableState + " local variable entry " + i + " is invalid");
}
}
}