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


The following commit(s) were added to refs/heads/main by this push:
     new 7c46b303b1 ARTEMIS-4302 NPE on JournalTransaction::forget
7c46b303b1 is described below

commit 7c46b303b12fb140730eef5432d550685d21529a
Author: Clebert Suconic <clebertsuco...@apache.org>
AuthorDate: Fri Jun 2 09:57:29 2023 -0400

    ARTEMIS-4302 NPE on JournalTransaction::forget
---
 artemis-journal/pom.xml                            |  5 ++++
 .../core/journal/impl/JournalTransaction.java      | 11 ++++----
 .../journal/impl/JournalTransactionForget.java     | 29 ++++++++++++++++++++++
 3 files changed, 40 insertions(+), 5 deletions(-)

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 @@
          <artifactId>junit</artifactId>
          <scope>test</scope>
       </dependency>
+      <dependency>
+         <groupId>org.mockito</groupId>
+         <artifactId>mockito-core</artifactId>
+         <scope>test</scope>
+      </dependency>
       <dependency>
          <groupId>org.apache.activemq</groupId>
          <artifactId>artemis-unit-test-support</artifactId>
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

Reply via email to