Skip to content

Commit

Permalink
Fix NPE in InstrumentedHandler#doStop (Jetty 9, 10, 11)
Browse files Browse the repository at this point in the history
Fixes #3325
Refs #3133
Refs #3174
Refs #3175
  • Loading branch information
joschi committed May 30, 2023
1 parent 8cd308b commit 4ebfcf7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
Expand Up @@ -273,9 +273,12 @@ protected void doStop() throws Exception {
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_1M));
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_5M));
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_15M));
responseCodeMeters.keySet().stream()
.map(sc -> name(getMetricPrefix(), String.format("%d-responses", sc)))
.forEach(m -> metricRegistry.remove(m));

if (responseCodeMeters != null) {
responseCodeMeters.keySet().stream()
.map(sc -> name(getMetricPrefix(), String.format("%d-responses", sc)))
.forEach(metricRegistry::remove);
}
super.doStop();
}

Expand Down
Expand Up @@ -24,6 +24,7 @@

import static com.codahale.metrics.annotation.ResponseMeteredLevel.ALL;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

public class InstrumentedHandlerTest {
private final HttpClient client = new HttpClient();
Expand Down Expand Up @@ -111,6 +112,14 @@ public void responseTimesAreRecordedForBlockingResponses() throws Exception {
assertResponseTimesValid();
}

@Test
public void doStopDoesNotThrowNPE() throws Exception {
InstrumentedHandler handler = new InstrumentedHandler(registry, null, ALL);
handler.setHandler(new TestHandler());

assertThatCode(handler::doStop).doesNotThrowAnyException();
}

@Test
@Ignore("flaky on virtual machines")
public void responseTimesAreRecordedForAsyncResponses() throws Exception {
Expand Down
Expand Up @@ -273,9 +273,12 @@ protected void doStop() throws Exception {
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_1M));
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_5M));
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_15M));
responseCodeMeters.keySet().stream()
.map(sc -> name(getMetricPrefix(), String.format("%d-responses", sc)))
.forEach(m -> metricRegistry.remove(m));

if (responseCodeMeters != null) {
responseCodeMeters.keySet().stream()
.map(sc -> name(getMetricPrefix(), String.format("%d-responses", sc)))
.forEach(metricRegistry::remove);
}
super.doStop();
}

Expand Down
Expand Up @@ -24,6 +24,7 @@

import static com.codahale.metrics.annotation.ResponseMeteredLevel.ALL;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

public class InstrumentedHandlerTest {
private final HttpClient client = new HttpClient();
Expand Down Expand Up @@ -111,6 +112,14 @@ public void responseTimesAreRecordedForBlockingResponses() throws Exception {
assertResponseTimesValid();
}

@Test
public void doStopDoesNotThrowNPE() throws Exception {
InstrumentedHandler handler = new InstrumentedHandler(registry, null, ALL);
handler.setHandler(new TestHandler());

assertThatCode(handler::doStop).doesNotThrowAnyException();
}

@Test
@Ignore("flaky on virtual machines")
public void responseTimesAreRecordedForAsyncResponses() throws Exception {
Expand Down
Expand Up @@ -281,9 +281,12 @@ protected void doStop() throws Exception {
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_1M));
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_5M));
metricRegistry.remove(name(prefix, NAME_PERCENT_5XX_15M));
responseCodeMeters.keySet().stream()
.map(sc -> name(getMetricPrefix(), String.format("%d-responses", sc)))
.forEach(m -> metricRegistry.remove(m));

if (responseCodeMeters != null) {
responseCodeMeters.keySet().stream()
.map(sc -> name(getMetricPrefix(), String.format("%d-responses", sc)))
.forEach(metricRegistry::remove);
}
super.doStop();
}

Expand Down
Expand Up @@ -24,6 +24,7 @@

import static com.codahale.metrics.annotation.ResponseMeteredLevel.ALL;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

public class InstrumentedHandlerTest {
private final HttpClient client = new HttpClient();
Expand Down Expand Up @@ -111,6 +112,14 @@ public void responseTimesAreRecordedForBlockingResponses() throws Exception {
assertResponseTimesValid();
}

@Test
public void doStopDoesNotThrowNPE() throws Exception {
InstrumentedHandler handler = new InstrumentedHandler(registry, null, ALL);
handler.setHandler(new TestHandler());

assertThatCode(handler::doStop).doesNotThrowAnyException();
}

@Test
@Ignore("flaky on virtual machines")
public void responseTimesAreRecordedForAsyncResponses() throws Exception {
Expand Down

0 comments on commit 4ebfcf7

Please sign in to comment.