private boolean isNullTestedClose(ClassContext classContext, ALOAD load, InstructionHandle nextHandle, Instruction next) {
if (!(next instanceof IFNULL)) {
return false;
}
IFNULL ifNull = (IFNULL) next;
InstructionHandle nextNextHandle = nextHandle.getNext(); // aload
if (nextNextHandle == null) {
return false;
}
Instruction nextInstruction = nextNextHandle.getInstruction();
if (!(nextInstruction instanceof ALOAD)) {
return false;
}
ALOAD nextLoad = (ALOAD) nextInstruction;
if (load.getIndex() != nextLoad.getIndex()) {
return false;
}
InstructionHandle nextNextNextHandle = nextNextHandle.getNext(); // invoke
if (nextNextNextHandle == null) {
return false;
}
Instruction nextNextNextInstruction = nextNextNextHandle.getInstruction();
if (!(nextNextNextInstruction instanceof INVOKEVIRTUAL)) {
return false;
}
INVOKEVIRTUAL invokeVirtual = (INVOKEVIRTUAL) nextNextNextInstruction;
String methodName = invokeVirtual.getMethodName(classContext.getConstantPoolGen());
String methodSig = invokeVirtual.getSignature(classContext.getConstantPoolGen());
if (!methodName.equals("close")) {
return false;
}
if (!methodSig.equals("()V")) {
return false;
}
InstructionHandle nextNextNextNextHandle = nextNextNextHandle.getNext(); // after
if (ifNull.getTarget() != nextNextNextNextHandle) {
return false;
}
return true;