From 781e4c460d7e6751b75d603f853949641a894b1b Mon Sep 17 00:00:00 2001 From: Jiri Danek Date: Thu, 25 Apr 2019 16:14:27 +0200 Subject: [PATCH] ARTEMIS-2320 'while' statement does not loop --- .../artemis/core/server/impl/QueueImpl.java | 14 +++++--------- .../artemis/common/SpawnedJMSServer.java | 18 ++++++++---------- 2 files changed, 13 insertions(+), 19 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 fac18ef85a..1b49e08b48 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 @@ -3748,16 +3748,12 @@ public class QueueImpl extends CriticalComponentImpl implements Queue { } } - while (true) { - if (messagesIterator != null && messagesIterator.hasNext()) { - MessageReference msg = messagesIterator.next(); - if (msg.isPaged()) { - previouslyBrowsed.add(((PagedReference) msg).getPosition()); - } - return msg; - } else { - break; + if (messagesIterator != null && messagesIterator.hasNext()) { + MessageReference msg = messagesIterator.next(); + if (msg.isPaged()) { + previouslyBrowsed.add(((PagedReference) msg).getPosition()); } + return msg; } if (getPagingIterator() != null) { while (getPagingIterator().hasNext()) { diff --git a/tests/joram-tests/src/test/java/org/apache/activemq/artemis/common/SpawnedJMSServer.java b/tests/joram-tests/src/test/java/org/apache/activemq/artemis/common/SpawnedJMSServer.java index 3e559e87cb..d80d9c9f53 100644 --- a/tests/joram-tests/src/test/java/org/apache/activemq/artemis/common/SpawnedJMSServer.java +++ b/tests/joram-tests/src/test/java/org/apache/activemq/artemis/common/SpawnedJMSServer.java @@ -48,16 +48,14 @@ public class SpawnedJMSServer { System.out.println("OK"); - String line = null; - while ((line = br.readLine()) != null) { - if ("STOP".equals(line.trim())) { - stopServer(); - System.out.println("Server stopped"); - System.exit(0); - } else { - // stop anyway but with an error status - System.exit(1); - } + String line = br.readLine(); + if (line != null && "STOP".equals(line.trim())) { + stopServer(); + System.out.println("Server stopped"); + System.exit(0); + } else { + // stop anyway but with an error status + System.exit(1); } } catch (Throwable t) { t.printStackTrace();