diff --git a/artemis-journal/pom.xml b/artemis-journal/pom.xml index 729492e71e..d3700ec5d5 100644 --- a/artemis-journal/pom.xml +++ b/artemis-journal/pom.xml @@ -79,6 +79,11 @@ junit test + + org.mockito + mockito-core + test + org.apache.activemq artemis-unit-test-support diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalTransaction.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalTransaction.java index 7fb104df4b..c7c5deb97e 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalTransaction.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalTransaction.java @@ -356,12 +356,13 @@ public class JournalTransaction { * Used by load, when the transaction was not loaded correctly */ public void forget() { - // The transaction was not committed or rolled back in the file, so we - // reverse any pos counts we added - for (JournalFile jf : pendingFiles) { - jf.decPosCount(); + if (pendingFiles != null) { + // The transaction was not committed or rolled back in the file, so we + // reverse any pos counts we added + for (JournalFile jf : pendingFiles) { + jf.decPosCount(); + } } - } @Override diff --git a/artemis-journal/src/test/java/org/apache/activemq/artemis/core/journal/impl/JournalTransactionForget.java b/artemis-journal/src/test/java/org/apache/activemq/artemis/core/journal/impl/JournalTransactionForget.java new file mode 100644 index 0000000000..ff0aba1c6e --- /dev/null +++ b/artemis-journal/src/test/java/org/apache/activemq/artemis/core/journal/impl/JournalTransactionForget.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.core.journal.impl; + +import org.junit.Test; +import org.mockito.Mockito; + +public class JournalTransactionForget { + @Test + public void testForgetTX() { + JournalTransaction transaction = new JournalTransaction(1, Mockito.mock(JournalRecordProvider.class)); + transaction.forget(); + } +} \ No newline at end of file