Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in InstrumentedHandler#doStop (Jetty 9, 10, 11) #3379

Merged
merged 1 commit into from May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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