示例#1
0
  @Override
  public void visitCode(Code obj) {
    Method m = getMethod();
    if (m.getReturnType() == Type.VOID) {
      return;
    }

    stack.resetForMethodEntry(this);
    ifBlocks.clear();
    activeUnconditional = null;

    CodeException[] ces = obj.getExceptionTable();
    if (CollectionUtils.isEmpty(ces)) {
      catchPCs = null;
    } else {
      catchPCs = new BitSet();
      for (CodeException ce : ces) {
        catchPCs.set(ce.getHandlerPC());
      }
    }
    gotoBranchPCs.clear();
    casePositions.clear();
    lookingForResetOp = false;

    try {
      super.visitCode(obj);
    } catch (StopOpcodeParsingException e) {
      // reported an issue, so get out
    }
  }
  /**
   * implements the visitor to reset the stack and proceed for private methods
   *
   * @param obj the context object of the currently parsed code block
   */
  @Override
  public void visitCode(Code obj) {
    Method m = getMethod();
    int aFlags = m.getAccessFlags();
    if ((((aFlags & Constants.ACC_PRIVATE) != 0) || ((aFlags & Constants.ACC_STATIC) != 0))
        && ((aFlags & Constants.ACC_SYNTHETIC) == 0)
        && (!m.getSignature().endsWith(")Z"))) {
      stack.resetForMethodEntry(this);
      returnRegister = -1;
      returnConstant = null;
      registerConstants.clear();
      methodSuspect = true;
      returnPC = -1;
      super.visitCode(obj);
      if (methodSuspect && (returnConstant != null)) {
        BugInstance bi =
            new BugInstance(
                    this,
                    BugType.MRC_METHOD_RETURNS_CONSTANT.name(),
                    ((aFlags & Constants.ACC_PRIVATE) != 0) ? NORMAL_PRIORITY : LOW_PRIORITY)
                .addClass(this)
                .addMethod(this);
        if (returnPC >= 0) {
          bi.addSourceLine(this, returnPC);
        }

        bi.addString(returnConstant.toString());
        bugReporter.reportBug(bi);
      }
    }
  }
示例#3
0
 /**
  * implements the visitor to reset the stack
  *
  * @param obj the context object of the currently parsed code block
  */
 @Override
 public void visitCode(Code obj) {
   stack.resetForMethodEntry(this);
   regValueType.clear();
   state = State.SEEN_NOTHING;
   loopStart = -1;
   loopEnd = -1;
   super.visitCode(obj);
 }
  /**
   * overrides the visitor reset the stack
   *
   * @param obj the context object of the currently parsed code block
   */
  @Override
  public void visitCode(Code obj) {

    stack.resetForMethodEntry(this);
    localSpecialObjects.clear();
    sawTernary = false;
    super.visitCode(obj);

    for (Integer pc : localSpecialObjects.values()) {
      bugReporter.reportBug(
          makeLocalBugInstance().addClass(this).addMethod(this).addSourceLine(this, pc.intValue()));
    }
  }
  /**
   * implements the visitor to reset the stack
   *
   * @param obj the context object of the currently parsed code block
   */
  @Override
  public void visitCode(Code obj) {
    stack.resetForMethodEntry(this);
    super.visitCode(obj);

    for (Map.Entry<Integer, CollectionRegInfo> entry : syncRegs.entrySet()) {
      CollectionRegInfo cri = entry.getValue();
      if (!cri.getIgnore()) {
        bugReporter.reportBug(
            new BugInstance(this, "LSYC_LOCAL_SYNCHRONIZED_COLLECTION", cri.getPriority())
                .addClass(this)
                .addMethod(this)
                .addSourceLine(cri.getSourceLineAnnotation()));
      }
    }
  }
  /**
   * overrides the visitor to reset the stack for the new method, then checks if the immutability
   * field is set to immutable and if so reports it
   *
   * @param obj the context object of the currently parsed method
   */
  @Override
  public void visitCode(Code obj) {
    try {
      String signature = Type.getReturnType(getMethod().getSignature()).getSignature();
      if (signature.startsWith("L")
          && CollectionUtils.isListSetMap(signature.substring(1, signature.length() - 1))) {
        stack.resetForMethodEntry(this);
        imType = ImmutabilityType.UNKNOWN;
        super.visitCode(obj);

        if ((imType == ImmutabilityType.IMMUTABLE)
            || (imType == ImmutabilityType.POSSIBLY_IMMUTABLE)) {
          Method m = getMethod();
          Statistics.getStatistics()
              .addImmutabilityStatus(clsName, m.getName(), m.getSignature(), imType);
        }
      }
    } catch (ClassNotFoundException cnfe) {
      bugReporter.reportMissingClass(cnfe);
    }
  }
 /**
  * implements the visitor to reset the opcode stack
  *
  * @param obj the context object for the currently parsed code block
  */
 @Override
 public void visitCode(Code obj) {
   stack.resetForMethodEntry(this);
   super.visitCode(obj);
 }