Skip to content

Commit

Permalink
NPE during expiration check (fixes #842) (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored May 17, 2023
1 parent 8dfc265 commit 6a3448d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void slideAndInsert(Deque<GcEvent> 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
Expand All @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 6a3448d

Please sign in to comment.