ARTEMIS-4302 NPE on JournalTransaction::forget

This commit is contained in:
Clebert Suconic 2023-06-02 09:57:29 -04:00 committed by clebertsuconic
parent 5553b6264c
commit 7c46b303b1
3 changed files with 40 additions and 5 deletions

View File

@ -79,6 +79,11 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.activemq</groupId> <groupId>org.apache.activemq</groupId>
<artifactId>artemis-unit-test-support</artifactId> <artifactId>artemis-unit-test-support</artifactId>

View File

@ -356,12 +356,13 @@ public class JournalTransaction {
* Used by load, when the transaction was not loaded correctly * Used by load, when the transaction was not loaded correctly
*/ */
public void forget() { public void forget() {
// The transaction was not committed or rolled back in the file, so we if (pendingFiles != null) {
// reverse any pos counts we added // The transaction was not committed or rolled back in the file, so we
for (JournalFile jf : pendingFiles) { // reverse any pos counts we added
jf.decPosCount(); for (JournalFile jf : pendingFiles) {
jf.decPosCount();
}
} }
} }
@Override @Override

View File

@ -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();
}
}