Ejemplo n.º 1
0
  public boolean isStreamClose(
      BasicBlock basicBlock,
      InstructionHandle handle,
      ConstantPoolGen cpg,
      ResourceValueFrame frame,
      RepositoryLookupFailureCallback lookupFailureCallback) {
    if (!mightCloseStream(basicBlock, handle, cpg)) return false;

    Instruction ins = handle.getInstruction();

    if ((ins instanceof INVOKEVIRTUAL) || (ins instanceof INVOKEINTERFACE)) {
      // Does this instruction close the stream?
      InvokeInstruction inv = (InvokeInstruction) ins;

      if (!frame.isValid() || !getInstanceValue(frame, inv, cpg).isInstance()) return false;

      // It's a close if the invoked class is any subtype of the stream
      // base class.
      // (Basically, we may not see the exact original stream class,
      // even though it's the same instance.)
      try {
        String classClosed = inv.getClassName(cpg);
        return Hierarchy.isSubtype(classClosed, streamBase)
            || Hierarchy.isSubtype(streamBase, classClosed);
      } catch (ClassNotFoundException e) {
        lookupFailureCallback.reportMissingClass(e);
        return false;
      }
    }

    return false;
  }