diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/DaemonMemoryStatus.java b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/DaemonMemoryStatus.java index 8f44e42c4..94cbf93ef 100644 --- a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/DaemonMemoryStatus.java +++ b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/DaemonMemoryStatus.java @@ -160,7 +160,7 @@ private void slideAndInsert(Deque events, GcEvent event) { } public boolean isTrashing() { - if (strategy.heapUsageThreshold != 0 && strategy.thrashingThreshold != 0) { + if (strategy != null && strategy.heapUsageThreshold != 0 && strategy.thrashingThreshold != 0) { GcStats stats = heapStats(); return stats != null && stats.usedPercent >= strategy.heapUsageThreshold @@ -171,7 +171,7 @@ public boolean isTrashing() { } public boolean isHeapSpaceExhausted() { - if (strategy.heapUsageThreshold != 0 && strategy.heapRateThreshold != 0) { + if (strategy != null && strategy.heapUsageThreshold != 0 && strategy.heapRateThreshold != 0) { GcStats stats = heapStats(); return stats != null && stats.usedPercent >= strategy.heapUsageThreshold @@ -182,7 +182,7 @@ public boolean isHeapSpaceExhausted() { } public boolean isNonHeapSpaceExhausted() { - if (strategy.nonHeapUsageThreshold != 0) { + if (strategy != null && strategy.nonHeapUsageThreshold != 0) { GcStats stats = nonHeapStats(); return stats != null && stats.usedPercent >= strategy.nonHeapUsageThreshold; } else { diff --git a/daemon/src/test/java/org/mvndaemon/mvnd/daemon/DaemonMemoryStatusTest.java b/daemon/src/test/java/org/mvndaemon/mvnd/daemon/DaemonMemoryStatusTest.java new file mode 100644 index 000000000..4d7d72916 --- /dev/null +++ b/daemon/src/test/java/org/mvndaemon/mvnd/daemon/DaemonMemoryStatusTest.java @@ -0,0 +1,40 @@ +/* + * 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.mvndaemon.mvnd.daemon; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DaemonMemoryStatusTest { + + @Test + void testStrategy() { + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + try { + DaemonMemoryStatus status = new DaemonMemoryStatus(executor); + assertNotNull(status.strategy); + } finally { + executor.shutdownNow(); + } + } +}