diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/OpenGrokThreadFactory.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/OpenGrokThreadFactory.java index 85eceec0ef6..c8e5f318381 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/OpenGrokThreadFactory.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/OpenGrokThreadFactory.java @@ -26,6 +26,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; +import java.util.Objects; /** * ThreadFactory to be used throughout OpenGrok to make sure all threads have common prefix. @@ -45,7 +46,7 @@ public OpenGrokThreadFactory(String name) { @Override public Thread newThread(@NotNull Runnable runnable) { - Thread thread = Executors.defaultThreadFactory().newThread(runnable); + Thread thread = Executors.defaultThreadFactory().newThread(Objects.requireNonNull(runnable, "runnable")); thread.setName(PREFIX + threadPrefix + thread.getId()); return thread; } diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryReader.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryReader.java index 0083af42186..8ac67315ca6 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryReader.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryReader.java @@ -26,6 +26,7 @@ import java.io.Reader; import java.io.StringReader; import java.util.List; +import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.opengrok.indexer.util.IOUtils; @@ -47,7 +48,7 @@ public int read(char @NotNull [] cbuf, int off, int len) throws IOException { if (input == null) { input = createInternalReader(); } - return input.read(cbuf, off, len); + return input.read(Objects.requireNonNull(cbuf, "cbuf"), off, len); } @Override diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexCheck.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexCheck.java index 4849015c89a..0e05686eb34 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexCheck.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexCheck.java @@ -36,6 +36,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; @@ -101,7 +102,7 @@ public enum IndexCheckMode { * @param configuration configuration based on which to perform the check */ public IndexCheck(@NotNull Configuration configuration) { - this(configuration, null); + this(configuration, null); // configuration is guarded against null inside this constructor } /** @@ -111,7 +112,7 @@ public IndexCheck(@NotNull Configuration configuration) { * on whether projects are enabled in the configuration. */ public IndexCheck(@NotNull Configuration configuration, Collection projectNames) { - this.configuration = configuration; + this.configuration = Objects.requireNonNull(configuration, "configuration"); if (projectNames != null) { this.projectNames.addAll(projectNames); } diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java index 30f01531225..c68a2794d72 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java @@ -2124,7 +2124,7 @@ private static class CountingWriter extends Writer { @Override public void write(@NotNull char[] chars, int off, int len) throws IOException { - out.write(chars, off, len); + out.write(Objects.requireNonNull(chars), off, len); count += len; } diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/OpenGrokThreadFactoryTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/OpenGrokThreadFactoryTest.java new file mode 100644 index 00000000000..ed0f58235be --- /dev/null +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/OpenGrokThreadFactoryTest.java @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * See LICENSE.txt included in this distribution for the specific + * language governing permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at LICENSE.txt. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Portions Copyright (c) 2024, Heewon Lee . + */ +package org.opengrok.indexer.configuration; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class OpenGrokThreadFactoryTest { + @Test + void testNullRunnable() throws Exception { + assertThrows(NullPointerException.class, () -> { + OpenGrokThreadFactory factory = new OpenGrokThreadFactory(""); + factory.newThread(null); + }); + } +} \ No newline at end of file diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryReaderTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryReaderTest.java new file mode 100644 index 00000000000..1cd450474c7 --- /dev/null +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryReaderTest.java @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * See LICENSE.txt included in this distribution for the specific + * language governing permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at LICENSE.txt. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Portions Copyright (c) 2024, Heewon Lee . + */ +package org.opengrok.indexer.history; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class HistoryReaderTest { + @Test + void testNullCbuf() throws Exception { + assertThrows(NullPointerException.class, () -> { + HistoryReader historyReader = new HistoryReader(new History()); + historyReader.read(null, 0, 0); + }); + } +} \ No newline at end of file diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexCheckTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexCheckTest.java index 650bfd9c069..26780b5cea9 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexCheckTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexCheckTest.java @@ -255,4 +255,12 @@ void testMultipleTestsWithSameInstance() throws Exception { } } } + + @Test + void testNullConfiguration() throws Exception { + assertThrows(NullPointerException.class, () -> { + new IndexCheck(null); + } + ); + } }