From 58f368482241bcd3f16471c728411afb52b5d021 Mon Sep 17 00:00:00 2001 From: Robert Knutsson Date: Wed, 11 Dec 2024 15:10:58 +0100 Subject: [PATCH] NPE when Clean.apply called with null as first argument --- .../utils/memory/MemtableCleanerThread.java | 2 +- .../utils/memory/MemtableCleanerThreadTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/cassandra/utils/memory/MemtableCleanerThread.java b/src/java/org/apache/cassandra/utils/memory/MemtableCleanerThread.java index dbc23e576fcd..31449900d8ef 100644 --- a/src/java/org/apache/cassandra/utils/memory/MemtableCleanerThread.java +++ b/src/java/org/apache/cassandra/utils/memory/MemtableCleanerThread.java @@ -94,7 +94,7 @@ private Boolean apply(Boolean res, Throwable err) final int tasks = numPendingTasks.decrementAndGet(); // if the cleaning job was scheduled (res == true) or had an error, trigger again after decrementing the tasks - if ((res || err != null) && pool.needsCleaning()) + if (((res != null && res) || err != null) && pool.needsCleaning()) wait.signal(); if (err != null) diff --git a/test/unit/org/apache/cassandra/utils/memory/MemtableCleanerThreadTest.java b/test/unit/org/apache/cassandra/utils/memory/MemtableCleanerThreadTest.java index 2ce9a8ed7856..5fa3f45bc51d 100644 --- a/test/unit/org/apache/cassandra/utils/memory/MemtableCleanerThreadTest.java +++ b/test/unit/org/apache/cassandra/utils/memory/MemtableCleanerThreadTest.java @@ -35,6 +35,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.when; public class MemtableCleanerThreadTest @@ -111,6 +112,22 @@ public void testCleanerInvoked() throws Exception stopThread(); } + @Test + public void testCleanerError() throws Exception + { + when(pool.needsCleaning()).thenReturn(false); + AsyncPromise fut = new AsyncPromise<>(); + cleaner = () -> { + return fut; + }; + + Clean<> clean = new Clean<>(pool, cleaner); + + Boolean res = clean.apply(null, null); + + assertNull(res); + } + @Test public void testCleanerError() throws Exception {