コード例 #1
0
ファイル: Stream.java プロジェクト: KengoTODA/findbugs
  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;
  }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * edu.umd.cs.findbugs.classfile.IAnalysisEngine#analyze(edu.umd.cs.findbugs
   * .classfile.IAnalysisCache, java.lang.Object)
   */
  public LoadedFieldSet analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor)
      throws CheckedAnalysisException {
    MethodGen methodGen = getMethodGen(analysisCache, descriptor);
    if (methodGen == null) return null;
    InstructionList il = methodGen.getInstructionList();

    LoadedFieldSet loadedFieldSet = new LoadedFieldSet(methodGen);
    ConstantPoolGen cpg = getConstantPoolGen(analysisCache, descriptor.getClassDescriptor());

    for (InstructionHandle handle = il.getStart(); handle != null; handle = handle.getNext()) {
      Instruction ins = handle.getInstruction();
      short opcode = ins.getOpcode();
      try {
        if (opcode == Constants.INVOKESTATIC) {
          INVOKESTATIC inv = (INVOKESTATIC) ins;
          if (Hierarchy.isInnerClassAccess(inv, cpg)) {
            InnerClassAccess access = Hierarchy.getInnerClassAccess(inv, cpg);
            /*
             * if (access == null) {
             * System.out.println("Missing inner class access in " +
             * SignatureConverter.convertMethodSignature(methodGen)
             * + " at " + inv); }
             */
            if (access != null) {
              if (access.isLoad()) loadedFieldSet.addLoad(handle, access.getField());
              else loadedFieldSet.addStore(handle, access.getField());
            }
          }
        } else if (fieldInstructionOpcodeSet.get(opcode)) {
          boolean isLoad = (opcode == Constants.GETFIELD || opcode == Constants.GETSTATIC);
          XField field = Hierarchy.findXField((FieldInstruction) ins, cpg);
          if (field != null) {
            if (isLoad) loadedFieldSet.addLoad(handle, field);
            else loadedFieldSet.addStore(handle, field);
          }
        }
      } catch (ClassNotFoundException e) {
        AnalysisContext.currentAnalysisContext().getLookupFailureCallback().reportMissingClass(e);
      }
    }

    return loadedFieldSet;
  }