Uploaded image for project: 'ActiveMQ Artemis'
  1. ActiveMQ Artemis
  2. ARTEMIS-1408

FindBugs: Synchronization on java.util.concurrent objects in MQTTSessionState.java

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.4.0
    • 2.5.0
    • Broker, MQTT
    • None

    Description

      82   boolean addSubscription(MqttTopicSubscription subscription, WildcardConfiguration wildcardConfiguration) {
         	
      CID 1419151 (#1 of 1): JLM: Synchronization on java.util.concurrent objects (FB.JLM_JSR166_UTILCONCURRENT_MONITORENTER)
      1. defect: Synchronization performed on java.util.concurrent.ConcurrentHashMap.
       83      synchronized (subscriptions) {
       84         addressMessageMap.putIfAbsent(MQTTUtil.convertMQTTAddressFilterToCore(subscription.topicName(), wildcardConfiguration), new ConcurrentHashMap<Long, Integer>());
       85
       86         MqttTopicSubscription existingSubscription = subscriptions.get(subscription.topicName());
       87         if (existingSubscription != null) {
       88            if (subscription.qualityOfService().value() > existingSubscription.qualityOfService().value()) {
       89               subscriptions.put(subscription.topicName(), subscription);
       90               return true;
       91            }
       92         } else {
       93            subscriptions.put(subscription.topicName(), subscription);
       94            return true;
       95         }
       96      }
       97      return false;
       98   }
       99
      
      100   void removeSubscription(String address) {
         	
      CID 1419085 (#1 of 1): JLM: Synchronization on java.util.concurrent objects (FB.JLM_JSR166_UTILCONCURRENT_MONITORENTER)
      1. defect: Synchronization performed on java.util.concurrent.ConcurrentHashMap.
      101      synchronized (subscriptions) {
      102         subscriptions.remove(address);
      103         addressMessageMap.remove(address);
      104      }
      105   }
      

      JLM: Synchronization performed on util.concurrent instance (JLM_JSR166_UTILCONCURRENT_MONITORENTER)

      This method performs synchronization an object that is an instance of a class from the java.util.concurrent package (or its subclasses). Instances of these classes have their own concurrency control mechanisms that are orthogonal to the synchronization provided by the Java keyword synchronized. For example, synchronizing on an AtomicBoolean will not prevent other threads from modifying the AtomicBoolean.

      Such code may be correct, but should be carefully reviewed and documented, and may confuse people who have to maintain the code at a later date.

      http://findbugs.sourceforge.net/bugDescriptions.html#JLM_JSR166_UTILCONCURRENT_MONITORENTER

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            jbertram Justin Bertram
            jdanek Jiri Daněk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment