Class ResourceInMultipleThreadsDetector

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

public class ResourceInMultipleThreadsDetector extends OpcodeStackDetector
  • Field Details

    • bugReporter

      private final BugReporter bugReporter
    • synchronizedCollectionTypedFields

      private final Set<XField> synchronizedCollectionTypedFields
    • calledMethodsByMethods

      private final Map<XMethod,Set<XMethod>> calledMethodsByMethods
    • methodsUsedInThreads

      private final Set<XMethod> methodsUsedInThreads
    • fieldsUsedInThreads

      private final Map<XField,ResourceInMultipleThreadsDetector.FieldData> fieldsUsedInThreads
    • synchronizedBlock

      private boolean synchronizedBlock
    • firstPass

      private boolean firstPass
  • Constructor Details

    • ResourceInMultipleThreadsDetector

      public ResourceInMultipleThreadsDetector(BugReporter bugReporter)
  • Method Details

    • visit

      public void visit(org.apache.bcel.classfile.JavaClass obj)
      Overrides:
      visit in class BetterVisitor
    • visit

      public void visit(org.apache.bcel.classfile.Method method)
      Overrides:
      visit in class BetterVisitor
    • 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:
    • collectMethodsUsedInThreads

      private void collectMethodsUsedInThreads(int seen)
    • addToMethodsUsedInThreads

      private void addToMethodsUsedInThreads(XMethod methodToAdd)
    • isJavaRuntimeMethod

      private boolean isJavaRuntimeMethod()
      Ignore a special case where a Thread is passed to the java.lang.Runtime class, so it is used as a shutdown hook.
      Returns:
      true if the Thread is passed to the java.lang.Runtime class, false otherwise
    • getMethodFromBootstrap

      private Optional<org.apache.bcel.classfile.Method> getMethodFromBootstrap(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.ConstantInvokeDynamic constDyn)
    • collectFieldsUsedInThreads

      private void collectFieldsUsedInThreads(int seen) throws CheckedAnalysisException
      Throws:
      CheckedAnalysisException
    • isAtomicTypedField

      private boolean isAtomicTypedField(XField xField)
    • createOrUpdateFieldData

      private void createOrUpdateFieldData(XField xField, boolean putfield, org.apache.bcel.classfile.Method containerMethod, XMethod xMethod)
    • visitAfter

      public void visitAfter(org.apache.bcel.classfile.JavaClass javaClass)
      Overrides:
      visitAfter in class PreorderVisitor
    • isBug

      private static boolean isBug(ResourceInMultipleThreadsDetector.FieldData data)
      A bug is reported if the field is modified in multiple methods, it is not only accessed in synchronized blocks, and it is not a synchronized collection or an atomic typed field.
      Parameters:
      data - the field data
      Returns:
      true if the field is a bug, false otherwise
    • resetState

      private void resetState()