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
This commit is contained in:
Clebert Suconic 2015-04-09 14:59:56 -04:00
parent 238b2fe094
commit 41b823be7e
1 changed files with 4 additions and 3 deletions

View File

@ -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());
}
}
}