diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java index 6d3fed8523..e6739d393c 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursor.java @@ -148,6 +148,8 @@ public class FilePendingMessageCursor extends AbstractPendingMessageCursor imple flushToDisk(); } } + // ensure any memory ref is released + iter = null; } @Override diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursorTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursorTestSupport.java index 5f67d625ed..123263d95b 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursorTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursorTestSupport.java @@ -26,10 +26,9 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class FilePendingMessageCursorTestSupport { @@ -70,4 +69,21 @@ public class FilePendingMessageCursorTestSupport { assertFalse("cursor is not full", underTest.isFull()); } + @Test + public void testResetClearsIterator() throws Exception { + createBrokerWithTempStoreLimit(); + + underTest = new FilePendingMessageCursor(brokerService.getBroker(), "test", false); + // ok to add + underTest.addMessageLast(QueueMessageReference.NULL_MESSAGE); + + underTest.reset(); + underTest.release(); + + try { + underTest.hasNext(); + fail("expect npe on use of iterator after release"); + } catch (NullPointerException expected) {} + } + }