Class ResourceInMultipleThreadsDetector

    • Field Detail

      • synchronizedCollectionTypedFields

        private final java.util.Set<XField> synchronizedCollectionTypedFields
      • methodsUsedInThreads

        private final java.util.Set<MethodDescriptor> methodsUsedInThreads
      • synchronizedBlock

        private boolean synchronizedBlock
      • firstPass

        private boolean firstPass
    • Constructor Detail

      • ResourceInMultipleThreadsDetector

        public ResourceInMultipleThreadsDetector​(BugReporter bugReporter)
    • Method Detail

      • 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
      • collectMethodsUsedInThreads

        private void collectMethodsUsedInThreads​(int seen)
      • 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 java.util.Optional<MethodDescriptor> getMethodFromBootstrap​(org.apache.bcel.classfile.JavaClass javaClass,
                                                                            org.apache.bcel.classfile.ConstantInvokeDynamic constDyn)
      • isAtomicTypedField

        private boolean isAtomicTypedField​(XField xField)
      • createOrUpdateFieldData

        private void createOrUpdateFieldData​(XField xField,
                                             boolean putfield,
                                             org.apache.bcel.classfile.Method method,
                                             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()