@Override
 public void visit(Code obj) {
   sawSuperFinalize = false;
   super.visit(obj);
   bugAccumulator.reportAccumulatedBugs();
   if (!getMethodName().equals("finalize") || !getMethodSig().equals("()V")) return;
   String overridesFinalizeIn =
       Lookup.findSuperImplementor(getDottedClassName(), "finalize", "()V", bugReporter);
   boolean superHasNoFinalizer = overridesFinalizeIn.equals("java.lang.Object");
   // System.out.println("superclass: " + superclassName);
   if (obj.getCode().length == 1) {
     if (superHasNoFinalizer) {
       if (!getMethod().isFinal())
         bugReporter.reportBug(
             new BugInstance(this, "FI_EMPTY", NORMAL_PRIORITY).addClassAndMethod(this));
     } else
       bugReporter.reportBug(
           new BugInstance(this, "FI_NULLIFY_SUPER", NORMAL_PRIORITY)
               .addClassAndMethod(this)
               .addClass(overridesFinalizeIn));
   } else if (obj.getCode().length == 5 && sawSuperFinalize)
     bugReporter.reportBug(
         new BugInstance(this, "FI_USELESS", NORMAL_PRIORITY).addClassAndMethod(this));
   else if (!sawSuperFinalize && !superHasNoFinalizer)
     bugReporter.reportBug(
         new BugInstance(this, "FI_MISSING_SUPER_CALL", NORMAL_PRIORITY)
             .addClassAndMethod(this)
             .addClass(overridesFinalizeIn));
 }
  /**
   * overrides the visitor to initialize and tear down the opcode stack
   *
   * @param classContext the context object of the currently parsed class
   */
  @Override
  public void visitClassContext(ClassContext classContext) {
    try {
      String clsName = classContext.getJavaClass().getClassName();
      isInnerClass = clsName.contains("$");

      clsSignature = SignatureUtils.classToSignature(clsName);
      stack = new OpcodeStack();
      localSpecialObjects = new HashMap<>();
      fieldSpecialObjects = new HashMap<>();
      super.visitClassContext(classContext);

      if (!isInnerClass && !fieldSpecialObjects.isEmpty()) {

        for (Map.Entry<String, String> entry : fieldSpecialObjects.entrySet()) {
          String fieldName = entry.getKey();
          String signature = entry.getValue();
          bugReporter.reportBug(
              makeFieldBugInstance().addClass(this).addField(clsName, fieldName, signature, false));
        }
      }
    } finally {
      stack = null;
      localSpecialObjects = null;
      fieldSpecialObjects = null;
    }
  }
Esempio n. 3
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 state
  *
  * @param obj the context object of the currently parsed code block
  */
 @Override
 public void visitCode(Code obj) {
   if (prescreen(getMethod())) {
     state = State.SAW_NOTHING;
     super.visitCode(obj);
   }
 }
  /**
   * 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);
      }
    }
  }
 /**
  * implements the listener to set up and tear down the opcode stack
  *
  * @param classContext the context object of the currently parsed class
  */
 @Override
 public void visitClassContext(ClassContext classContext) {
   try {
     stack = new OpcodeStack();
     super.visitClassContext(classContext);
   } finally {
     stack = null;
   }
 }
Esempio n. 7
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);
 }
 @Override
 public void visitClassContext(ClassContext context) {
   try {
     stack = new OpcodeStack();
     clsName = context.getJavaClass().getClassName();
     super.visitClassContext(context);
   } finally {
     stack = null;
   }
 }
 @Override
 public void visitClassContext(ClassContext classContext) {
   try {
     stack = new OpcodeStack();
     registerConstants = new HashMap<Integer, Object>();
     super.visitClassContext(classContext);
   } finally {
     stack = null;
     registerConstants = null;
   }
 }
 /**
  * implements the visitor to create and clear the stack and syncRegs
  *
  * @param classContext the context object of the currently parsed class
  */
 @Override
 public void visitClassContext(ClassContext classContext) {
   try {
     stack = new OpcodeStack();
     syncRegs = new HashMap<Integer, CollectionRegInfo>();
     classVersion = classContext.getJavaClass().getMajor();
     super.visitClassContext(classContext);
   } finally {
     stack = null;
     syncRegs = null;
   }
 }
  /**
   * 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()));
    }
  }
Esempio n. 12
0
 @Override
 public void visitClassContext(ClassContext classContext) {
   try {
     JavaClass cls = classContext.getJavaClass();
     if (cls.getMajor() >= MAJOR_1_4) {
       stack = new OpcodeStack();
       regValueType = new HashMap<Integer, State>();
       super.visitClassContext(classContext);
     }
   } finally {
     stack = null;
     regValueType = null;
   }
 }
Esempio n. 13
0
 @Override
 public void visitClassContext(ClassContext classContext) {
   try {
     stack = new OpcodeStack();
     ifBlocks = new ArrayDeque<>();
     gotoBranchPCs = new BitSet();
     casePositions = new ArrayDeque<>();
     super.visitClassContext(classContext);
   } finally {
     stack = null;
     ifBlocks = null;
     catchPCs = null;
     gotoBranchPCs = null;
     casePositions = null;
   }
 }
  /**
   * 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);
    }
  }
Esempio n. 16
0
 @Override
 public void visit(Code obj) {
   if (!directChildOfTestCase
       && (getMethodName().equals("setUp") || getMethodName().equals("tearDown"))
       && !getMethod().isPrivate()
       && getMethodSig().equals("()V")) {
     sawSuperCall = false;
     super.visit(obj);
     if (sawSuperCall) {
       return;
     }
     JavaClass we =
         Lookup.findSuperImplementor(getThisClass(), getMethodName(), "()V", bugReporter);
     if (we != null && !we.getClassName().equals("junit.framework.TestCase")) {
       // OK, got a bug
       int offset = 0;
       if (getMethodName().equals("tearDown")) {
         offset = obj.getCode().length - 1;
       }
       Method superMethod = Lookup.findImplementation(we, getMethodName(), "()V");
       Code superCode = superMethod.getCode();
       if (superCode != null && superCode.getCode().length > 3) {
         bugReporter.reportBug(
             new BugInstance(
                     this,
                     getMethodName().equals("setUp")
                         ? "IJU_SETUP_NO_SUPER"
                         : "IJU_TEARDOWN_NO_SUPER",
                     NORMAL_PRIORITY)
                 .addClassAndMethod(this)
                 .addMethod(we, superMethod)
                 .describe(MethodAnnotation.METHOD_OVERRIDDEN)
                 .addSourceLine(this, offset));
       }
     }
   }
 }
 /**
  * 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);
 }
 @Override
 public void visit(Code code) {
   binpushPC = Integer.MIN_VALUE;
   numCompareBlockStartPC = 0;
   super.visit(code);
 }
Esempio n. 19
0
 @Override
 public void visit(Code obj) {
   if (inConstructor) {
     super.visit(obj);
   }
 }
 @Override
 public void visit(Code obj) {
   super.visit(obj);
   bugAccumulator.reportAccumulatedBugs();
 }
 @Override
 public void visit(Method obj) {
   localsWithCurrentThreadValue = new BitSet();
   state = SEEN_NOTHING;
   super.visit(obj);
 }