From 58ff6e60fb0ce351b19e36baddd5a6dbcb94e768 Mon Sep 17 00:00:00 2001 From: Nugusbayev Kanagat Date: Tue, 5 Dec 2023 12:03:54 +0600 Subject: [PATCH] wrapped with try/finally block. removed static import --- .../v5/helper/FutureCallbackWrapper.java | 27 ++++++++++++------- ...cheHttpAsyncClientInstrumentationTest.java | 7 +++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/FutureCallbackWrapper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/FutureCallbackWrapper.java index 7c0b52e81e..498d66e6d1 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/FutureCallbackWrapper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/FutureCallbackWrapper.java @@ -54,10 +54,13 @@ public void completed(T result) { try { finishSpan(null); } finally { - if (delegate != null) { - delegate.completed(result); + try { + if (delegate != null) { + delegate.completed(result); + } + } finally { + helper.recycle(this); } - helper.recycle(this); } } @@ -66,10 +69,13 @@ public void failed(Exception ex) { try { finishSpan(ex); } finally { - if (delegate != null) { - delegate.failed(ex); + try { + if (delegate != null) { + delegate.failed(ex); + } + } finally { + helper.recycle(this); } - helper.recycle(this); } } @@ -87,10 +93,13 @@ public void cancelled() { try { finishSpan(null); } finally { - if (delegate != null) { - delegate.cancelled(); + try { + if (delegate != null) { + delegate.cancelled(); + } + } finally { + helper.recycle(this); } - helper.recycle(this); } } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/test/java/co/elastic/apm/agent/httpclient/v5/ApacheHttpAsyncClientInstrumentationTest.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/test/java/co/elastic/apm/agent/httpclient/v5/ApacheHttpAsyncClientInstrumentationTest.java index 2c8bc30654..4b0ccc72eb 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/test/java/co/elastic/apm/agent/httpclient/v5/ApacheHttpAsyncClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/test/java/co/elastic/apm/agent/httpclient/v5/ApacheHttpAsyncClientInstrumentationTest.java @@ -31,7 +31,6 @@ import org.apache.hc.core5.concurrent.FutureCallback; import org.apache.hc.core5.http.ProtocolException; import org.apache.hc.core5.net.URIAuthority; -import org.assertj.core.api.Assertions; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -103,7 +102,7 @@ public void testSpanFinishOnEarlyException() throws Exception { reporter.resetChecks(); } assertThat(reporter.getFirstSpan(500)).isNotNull(); - Assertions.assertThat(reporter.getSpans()).hasSize(1); + assertThat(reporter.getSpans()).hasSize(1); } @Test @@ -117,7 +116,7 @@ public void testSpanFinishWithIllegalProtocol() throws Exception { assertThat(firstSpan).isNotNull(); assertThat(firstSpan.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(firstSpan.getNameAsString()).isEqualTo("GET localhost"); - Assertions.assertThat(reporter.getSpans()).hasSize(1); + assertThat(reporter.getSpans()).hasSize(1); } @Test @@ -138,7 +137,7 @@ public void testSpanFinishWithIllegalUrl() throws Exception { assertThat(firstSpan).isNotNull(); assertThat(firstSpan.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(firstSpan.getNameAsString()).isEqualTo("GET "); - Assertions.assertThat(reporter.getSpans()).hasSize(1); + assertThat(reporter.getSpans()).hasSize(1); } /**