Class FindImproperSynchronization

    • Field Detail

      • WRAPPER_IMPLEMENTATIONS

        private static final java.util.Map<MethodDescriptor,​java.lang.Integer> WRAPPER_IMPLEMENTATIONS
      • IMMUTABLE_RETURNERS

        private static final java.util.Set<java.lang.String> IMMUTABLE_RETURNERS
      • exposingMethods

        private final java.util.Set<XMethod> exposingMethods
      • synchronizedMethods

        private final java.util.Set<XMethod> synchronizedMethods
      • declaredLockObjects

        private final java.util.Map<XField,​XMethod> declaredLockObjects
      • inheritedLockObjects

        private final java.util.Map<XField,​XMethod> inheritedLockObjects
      • declaredInheritedFieldAccessingMethods

        private final MultiMap<XField,​XMethod> declaredInheritedFieldAccessingMethods
      • potentialObjectBugContainingMethods

        private final MultiMap<XField,​XMethod> potentialObjectBugContainingMethods
      • potentialInheritedBugContainingMethods

        private final MultiMap<XField,​XMethod> potentialInheritedBugContainingMethods
      • badBackingCollections

        private final java.util.Set<XField> badBackingCollections
      • inheritableBackingCollections

        private final java.util.Set<XField> inheritableBackingCollections
      • collectionAccessorsInHierarchy

        private final MultiMap<XField,​XMethod> collectionAccessorsInHierarchy
    • Constructor Detail

      • FindImproperSynchronization

        public FindImproperSynchronization​(BugReporter bugReporter)
    • Method Detail

      • isWrapperImplementation

        private static boolean isWrapperImplementation​(MethodDescriptor methodDescriptor)
      • getStackOffset

        private static java.lang.Integer getStackOffset​(MethodDescriptor methodDescriptor)
      • isImmutableReturner

        private static boolean isImmutableReturner​(java.lang.String signature)
      • visit

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

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

        public void visitAfter​(org.apache.bcel.classfile.JavaClass obj)
        Overrides:
        visitAfter in class PreorderVisitor
      • isCollection

        private boolean isCollection​(org.apache.bcel.generic.Type type)
      • isCollection

        private boolean isCollection​(XField field)
      • isMethodCall

        private boolean isMethodCall​(org.apache.bcel.generic.Instruction instruction)
      • isPackagePrivate

        private boolean isPackagePrivate​(XField field)
      • isInitializerMethod

        private boolean isInitializerMethod​(java.lang.String methodName)
      • isInherited

        private boolean isInherited​(XField lockObject)
        Check if the lock object is inherited from the current class. To ensure no false positives, we compare only the outer class name if the lock object is contained in an inner class. Only checking equality is enough, since the lock object is a field declared in a class. That means if the declaring class of the lock object is the same as the current class, the lock object is not inherited.
        Parameters:
        lockObject - the lock object to check for inheritance
        Returns:
        true if the lock object is inherited from the current class, false otherwise
      • analyzeWrappedField

        private void analyzeWrappedField​(org.apache.bcel.classfile.Method currentMethod,
                                         ClassContext classContext,
                                         Location location,
                                         org.apache.bcel.generic.InstructionHandle handle,
                                         XField assignedField,
                                         java.lang.Integer stackOffsetForWrapperMethodParameter)
        Analyze a wrapping method call and check if this the creation of a binding collection. There are specific methods that use their parameters to create a new collections, but they maintain a reference to the original collection. When a collection is wrapped by such a method and the result is assigned to a field, the wrapped collections becomes a backing collection.
        Parameters:
        currentMethod - the method in which the wrapping method call is located
        classContext - the class context of the currently analyzed class, in which the wrapping method call is located
        location - the location of the wrapping method call
        handle - the instruction handle of the wrapping method call
        assignedField - the field to which the result of the wrapping method call is assigned
        stackOffsetForWrapperMethodParameter - the stack offset of the wrapped collection parameter of the wrapping method call
      • analyzeAssignmentsInHierarchy

        private void analyzeAssignmentsInHierarchy​(XField collectionLockObject)
      • checkLockUsageInHierarchy

        private void checkLockUsageInHierarchy​(XField field,
                                               XMethod exposingMethod)
      • findExposureInHierarchy

        private java.util.Set<XMethod> findExposureInHierarchy​(XField lockObject)
                                                        throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • findLockUsageInHierarchy

        private java.util.Set<XMethod> findLockUsageInHierarchy​(XField field)
                                                         throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • buildMethodsMessage

        private java.lang.String buildMethodsMessage​(java.util.Collection<XMethod> methods)
      • reportExposingLockObjectBugs

        private void reportExposingLockObjectBugs​(XField lock,
                                                  java.util.Collection<XMethod> lockUsingMethods,
                                                  java.util.Collection<XMethod> exposingMethods)
      • reportAccessibleObjectBug

        private void reportAccessibleObjectBug​(XField lock,
                                               java.util.Collection<XMethod> definedLockAccessors,
                                               java.util.Map<XField,​XMethod> synchronizedMethods)
      • reportInheritedObjectBugs

        private void reportInheritedObjectBugs​(XField lock,
                                               java.util.Collection<XMethod> synchronizedMethods)
      • reportObjectBugs

        private void reportObjectBugs​(XField lock,
                                      java.util.Collection<XMethod> synchronizedMethods)
      • clearState

        private void clearState()