Skip to content

Commit

Permalink
ARTEMIS-4233 Avoiding holder.iter=null with a compile time validation
Browse files Browse the repository at this point in the history
  • Loading branch information
clebertsuconic committed Apr 6, 2023
1 parent d9d727b commit 23bbf76
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3093,9 +3093,21 @@ private boolean deliver() {
break;
}

ConsumerHolder<? extends Consumer> holder;
final ConsumerHolder<? extends Consumer> holder;
final LinkedListIterator<MessageReference> holderIterator;
if (consumers.hasNext()) {
holder = consumers.next();
if (holder == null) {
// this shouldn't happen, however I'm adding this check just in case
logger.debug("consumers.next() returned null.");
consumers.remove();
deliverAsync(true);
return false;
}
if (holder.iter == null) {
holder.iter = messageReferences.iterator();
}
holderIterator = holder.iter;
} else {
pruneLastValues();
break;
Expand All @@ -3112,12 +3124,8 @@ private boolean deliver() {
return false;
}

if (holder.iter == null) {
holder.iter = messageReferences.iterator();
}

if (holder.iter.hasNext()) {
ref = holder.iter.next();
if (holderIterator.hasNext()) {
ref = holderIterator.next();
} else {
ref = null;
}
Expand Down Expand Up @@ -3167,7 +3175,7 @@ private boolean deliver() {
consumers.reset();
} else if (status == HandleStatus.BUSY) {
try {
holder.iter.repeat();
holderIterator.repeat();
} catch (NoSuchElementException e) {
// this could happen if there was an exception on the queue handling
// and it returned BUSY because of that exception
Expand Down

0 comments on commit 23bbf76

Please sign in to comment.