Repository: activemq-6
Updated Branches:
  refs/heads/master 238b2fe09 -> d9c9fc0e9


Fixing race on PageSubscriptionImpl

I have seen a NPE in a few unit tests that were caused by currenDelivery 
changing between these two steps:

i - if (currentDelivery != null)
ii - .... currentDelivery.getPos();

instead of adding extra synchronization I'm caching the currentValue what would 
been enough on this case.

This is just to avoid NPEs


Project: http://git-wip-us.apache.org/repos/asf/activemq-6/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-6/commit/41b823be
Tree: http://git-wip-us.apache.org/repos/asf/activemq-6/tree/41b823be
Diff: http://git-wip-us.apache.org/repos/asf/activemq-6/diff/41b823be

Branch: refs/heads/master
Commit: 41b823be7ebcb83d0f8f24e805b6f4433ce5a049
Parents: 238b2fe
Author: Clebert Suconic <clebertsuco...@apache.org>
Authored: Thu Apr 9 14:59:56 2015 -0400
Committer: Clebert Suconic <clebertsuco...@apache.org>
Committed: Thu Apr 9 15:00:20 2015 -0400

----------------------------------------------------------------------
 .../core/paging/cursor/impl/PageSubscriptionImpl.java         | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-6/blob/41b823be/activemq-server/src/main/java/org/apache/activemq/core/paging/cursor/impl/PageSubscriptionImpl.java
----------------------------------------------------------------------
diff --git 
a/activemq-server/src/main/java/org/apache/activemq/core/paging/cursor/impl/PageSubscriptionImpl.java
 
b/activemq-server/src/main/java/org/apache/activemq/core/paging/cursor/impl/PageSubscriptionImpl.java
index 42eeed8..5bf36e6 100644
--- 
a/activemq-server/src/main/java/org/apache/activemq/core/paging/cursor/impl/PageSubscriptionImpl.java
+++ 
b/activemq-server/src/main/java/org/apache/activemq/core/paging/cursor/impl/PageSubscriptionImpl.java
@@ -1471,12 +1471,13 @@ final class PageSubscriptionImpl implements 
PageSubscription
       public void remove()
       {
          deliveredCount.incrementAndGet();
-         if (currentDelivery != null)
+         PagedReference delivery = currentDelivery;
+         if (delivery != null)
          {
-            PageCursorInfo info = 
PageSubscriptionImpl.this.getPageInfo(currentDelivery.getPosition());
+            PageCursorInfo info = 
PageSubscriptionImpl.this.getPageInfo(delivery.getPosition());
             if (info != null)
             {
-               info.remove(currentDelivery.getPosition());
+               info.remove(delivery.getPosition());
             }
          }
       }

Reply via email to