Class MethodReturnCheck

All Implemented Interfaces:
Detector, Priorities, UseAnnotationDatabase, org.apache.bcel.classfile.Visitor

public class MethodReturnCheck extends OpcodeStackDetector implements UseAnnotationDatabase
Look for calls to methods where the return value is erroneously ignored. This detector is meant as a simpler and faster replacement for BCPMethodReturnCheck.
  • Field Details

    • DEBUG

      private static final boolean DEBUG
    • INVOKE_OPCODE_SET

      private static final BitSet INVOKE_OPCODE_SET
    • MOCKITO_VOID_STUBBING_METHODS

      private static final Set<String> MOCKITO_VOID_STUBBING_METHODS
    • BDD_MOCKITO_VOID_STUBBING_METHODS

      private static final Set<String> BDD_MOCKITO_VOID_STUBBING_METHODS
    • previousOpcodeWasNEW

      boolean previousOpcodeWasNEW
    • bugAccumulator

      private final BugAccumulator bugAccumulator
    • checkReturnAnnotationDatabase

      private CheckReturnAnnotationDatabase checkReturnAnnotationDatabase
    • callSeen

      private XMethod callSeen
    • state

      private MethodReturnCheck.State state
    • callPC

      private int callPC
    • noSideEffectMethods

      private final FindNoSideEffectMethods.NoSideEffectMethodsDatabase noSideEffectMethods
    • sawExcludedNSECall

      private boolean sawExcludedNSECall
    • sawMockitoInvoke

      private boolean sawMockitoInvoke
  • Constructor Details

    • MethodReturnCheck

      public MethodReturnCheck(BugReporter bugReporter)
  • Method Details

    • visitClassContext

      public void visitClassContext(ClassContext classContext)
      Description copied from interface: Detector
      Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
      Specified by:
      visitClassContext in interface Detector
      Overrides:
      visitClassContext in class BytecodeScanningDetector
      Parameters:
      classContext - the ClassContext
    • visitAfter

      public void visitAfter(org.apache.bcel.classfile.Code code)
      Description copied from class: PreorderVisitor
      Called after visiting a code attribute
      Overrides:
      visitAfter in class PreorderVisitor
      Parameters:
      code - Code that was just visited
    • badUseOfCompareResult

      private boolean badUseOfCompareResult(OpcodeStack.Item left, OpcodeStack.Item right)
    • sawOpcode

      public void sawOpcode(int seen)
      Description copied from class: OpcodeStackDetector

      By default, this method will not be called when stack is TOP. To change this behavior, override #beforeOpcode(int) and change to return true even if stack is TOP.

      see Using FindBugs for Research to learn lattice and what TOP means.

      Specified by:
      sawOpcode in class OpcodeStackDetector
      See Also:
    • isCallMockitoInvocation

      private boolean isCallMockitoInvocation(XMethod method)
    • isCallBDDMockitoInvocation

      private boolean isCallBDDMockitoInvocation(XMethod method)
    • sawMethodCallWithIgnoredReturnValue

      private void sawMethodCallWithIgnoredReturnValue()
    • isPop

      private boolean isPop(int seen)