You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2023/04/06 14:40:09 UTC
[activemq-artemis] 01/02: ARTEMIS-4233 Avoiding holder.iter=null with a compile time validation
This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
commit 23bbf76bdfdf56b3088b5149c152d05c86709717
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Mon Apr 3 09:55:48 2023 -0400
ARTEMIS-4233 Avoiding holder.iter=null with a compile time validation
---
.../artemis/core/server/impl/QueueImpl.java | 24 ++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
index e27b89eea2..39b71d5526 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/QueueImpl.java
@@ -3093,9 +3093,21 @@ public class QueueImpl extends CriticalComponentImpl implements Queue {
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;
@@ -3112,12 +3124,8 @@ public class QueueImpl extends CriticalComponentImpl implements Queue {
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;
}
@@ -3167,7 +3175,7 @@ public class QueueImpl extends CriticalComponentImpl implements Queue {
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