diff --git a/sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/LocalHttpClient.java b/sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/LocalHttpClient.java index 647b1994663e..cdedd598e27b 100644 --- a/sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/LocalHttpClient.java +++ b/sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/LocalHttpClient.java @@ -32,7 +32,7 @@ public Response send(HttpRequest request) { return new MockHttpResponse(request, success ? 200 : 400) { @Override - public void close() throws IOException { + public void close() { closeCalledOnResponse = true; super.close(); diff --git a/sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/ResponseBodyModeGeneration.java b/sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/ResponseBodyModeGeneration.java index 2138a16172ff..807c9e7847f5 100644 --- a/sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/ResponseBodyModeGeneration.java +++ b/sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/ResponseBodyModeGeneration.java @@ -15,8 +15,6 @@ import io.clientcore.core.implementation.http.HttpResponse; import io.clientcore.core.implementation.http.HttpResponseAccessHelper; import io.clientcore.core.models.binarydata.BinaryData; -import java.io.IOException; -import java.io.UncheckedIOException; import static io.clientcore.annotation.processor.templating.JavaParserTemplateProcessor.isPrimitiveOrWrapper; @@ -121,11 +119,7 @@ public static void generateResponseHandling(BlockStmt body, String returnTypeNam } private static void closeResponse(BlockStmt body) { - body.tryAddImportToParentCompilationUnit(IOException.class); - body.tryAddImportToParentCompilationUnit(UncheckedIOException.class); - - body.addStatement(StaticJavaParser.parseStatement("try { response.close(); }" - + "catch (IOException e) { throw LOGGER.logThrowableAsError(new UncheckedIOException(e)); }")); + body.addStatement(StaticJavaParser.parseStatement("response.close();")); } /** diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/Response.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/Response.java index 61d8559357f3..93db5d5b4387 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/Response.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/Response.java @@ -63,4 +63,9 @@ public interface Response extends Closeable { static Response create(HttpRequest request, int statusCode, HttpHeaders headers, T value) { return new HttpResponse<>(request, statusCode, headers, value); } + + /** + * Closes the response and releases any resources associated with it. + */ + void close(); } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/paging/PagedResponse.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/paging/PagedResponse.java index 527cf2f8ba1e..8f85c4d380d8 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/paging/PagedResponse.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/paging/PagedResponse.java @@ -8,7 +8,6 @@ import io.clientcore.core.http.models.Response; import io.clientcore.core.models.binarydata.BinaryData; -import java.io.IOException; import java.util.List; /** @@ -162,7 +161,7 @@ public BinaryData getBody() { * {@inheritDoc} */ @Override - public void close() throws IOException { + public void close() { if (body != null) { body.close(); } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicy.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicy.java index 28577c03b96c..cff67ad842d4 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicy.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpInstrumentationPolicy.java @@ -645,7 +645,7 @@ public BinaryData getBody() { } @Override - public void close() throws IOException { + public void close() { if (bufferedBody == null) { getBody(); } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpRedirectPolicy.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpRedirectPolicy.java index c61d33fc943f..6b359254c767 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpRedirectPolicy.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpRedirectPolicy.java @@ -11,8 +11,6 @@ import io.clientcore.core.instrumentation.logging.ClientLogger; import io.clientcore.core.instrumentation.logging.LoggingEvent; -import java.io.IOException; -import java.io.UncheckedIOException; import java.net.HttpURLConnection; import java.net.URI; import java.util.Collections; @@ -177,11 +175,7 @@ private void createRedirectRequest(Response redirectResponse) { redirectResponse.getRequest().getHeaders().remove(HttpHeaderName.AUTHORIZATION); redirectResponse.getRequest().setUri(redirectResponse.getHeaders().getValue(this.locationHeader)); - try { - redirectResponse.close(); - } catch (IOException e) { - throw LOGGER.logThrowableAsError(new UncheckedIOException(e)); - } + redirectResponse.close(); } private void logRedirect(ClientLogger logger, boolean lastAttempt, String redirectUri, int tryCount, diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpRetryPolicy.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpRetryPolicy.java index 19b2845c792e..654016f45d71 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpRetryPolicy.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/HttpRetryPolicy.java @@ -16,7 +16,6 @@ import io.clientcore.core.utils.configuration.Configuration; import java.io.IOException; -import java.io.UncheckedIOException; import java.net.HttpURLConnection; import java.time.DateTimeException; import java.time.Duration; @@ -210,12 +209,7 @@ private Response attempt(final HttpRequest httpRequest, final HttpPipelineNex final Duration delayDuration = determineDelayDuration(response, tryCount, delayFromHeaders); logRetry(logger.atVerbose(), tryCount, delayDuration, null, false, instrumentationContext); - - try { - response.close(); - } catch (IOException e) { - throw LOGGER.logThrowableAsError(new UncheckedIOException(e)); - } + response.close(); long millis = delayDuration.toMillis(); if (millis > 0) { diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/OAuthBearerTokenAuthenticationPolicy.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/OAuthBearerTokenAuthenticationPolicy.java index 2455ffdcc31c..73a2646e8c14 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/OAuthBearerTokenAuthenticationPolicy.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/http/pipeline/OAuthBearerTokenAuthenticationPolicy.java @@ -11,7 +11,6 @@ import io.clientcore.core.http.models.Response; import io.clientcore.core.instrumentation.logging.ClientLogger; -import java.io.IOException; import java.util.Objects; /** @@ -82,11 +81,7 @@ public Response process(HttpRequest httpRequest, HttpPipelineNextPolicy next) if (httpResponse.getStatusCode() == 401 && authHeader != null) { if (authorizeRequestOnChallenge(httpRequest, httpResponse)) { // body needs to be closed or read to the end to release the connection - try { - httpResponse.close(); - } catch (IOException e) { - throw LOGGER.logThrowableAsError(new RuntimeException(e)); - } + httpResponse.close(); return nextPolicy.process(); } else { return httpResponse; diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/http/HttpResponse.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/http/HttpResponse.java index 4989aca12d55..f24c74099af6 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/http/HttpResponse.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/http/HttpResponse.java @@ -8,7 +8,6 @@ import io.clientcore.core.http.models.Response; import io.clientcore.core.models.binarydata.BinaryData; -import java.io.IOException; import java.util.function.Function; /** @@ -165,7 +164,7 @@ private HttpResponse setBodyDeserializer(Function bodyDes } @Override - public void close() throws IOException { + public void close() { BinaryData body = getBody(); if (body != null) { body.close(); diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/http/rest/RestProxyImpl.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/http/rest/RestProxyImpl.java index 351116d4af42..c2cf0f16eae6 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/http/rest/RestProxyImpl.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/implementation/http/rest/RestProxyImpl.java @@ -350,11 +350,7 @@ private static Object handleRestResponseReturnType(Response response, Swagger final Type bodyType = TypeUtil.getRestResponseBodyType(entityType); if (TypeUtil.isTypeOrSubTypeOf(bodyType, Void.class)) { - try { - response.close(); - } catch (IOException e) { - throw LOGGER.logThrowableAsError(new UncheckedIOException(e)); - } + response.close(); return createResponseIfNecessary(response, entityType, null); } else { @@ -461,11 +457,7 @@ private static Object handleRestReturnType(Response response, SwaggerMethodPa final Object result; if (TypeUtil.isTypeOrSubTypeOf(returnType, void.class) || TypeUtil.isTypeOrSubTypeOf(returnType, Void.class)) { - try { - expectedResponse.close(); - } catch (IOException e) { - throw LOGGER.logThrowableAsError(new UncheckedIOException(e)); - } + expectedResponse.close(); result = null; } else { diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/BinaryData.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/BinaryData.java index 304d4ccf7111..636f37df018c 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/BinaryData.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/BinaryData.java @@ -808,4 +808,9 @@ public void writeTo(WritableByteChannel channel) throws IOException { public static BinaryData empty() { return BinaryData.EMPTY; } + + /** + * Closes the underlying resource of this {@link BinaryData} if it is closeable. + */ + public abstract void close(); } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ByteArrayBinaryData.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ByteArrayBinaryData.java index f2371a55efe2..377661aedfee 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ByteArrayBinaryData.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ByteArrayBinaryData.java @@ -78,7 +78,7 @@ public BinaryData toReplayableBinaryData() { } @Override - public void close() throws IOException { + public void close() { // no-op } } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ByteBufferBinaryData.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ByteBufferBinaryData.java index 50343af13c72..ef5bd21420c0 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ByteBufferBinaryData.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ByteBufferBinaryData.java @@ -101,7 +101,7 @@ private byte[] getBytes() { } @Override - public void close() throws IOException { + public void close() { // no-op } } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/FileBinaryData.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/FileBinaryData.java index 423c10b0107a..1862ba903728 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/FileBinaryData.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/FileBinaryData.java @@ -241,7 +241,7 @@ private byte[] getBytes() { } @Override - public void close() throws IOException { + public void close() { // Since this uses a Path, there is nothing to close, therefore no-op. } } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/InputStreamBinaryData.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/InputStreamBinaryData.java index cb61a9504131..1264bab84b5c 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/InputStreamBinaryData.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/InputStreamBinaryData.java @@ -213,7 +213,11 @@ private byte[] getBytes() { } @Override - public void close() throws IOException { - content.get().close(); + public void close() { + try { + content.get().close(); + } catch (IOException e) { + throw LOGGER.logThrowableAsError(new UncheckedIOException(e)); + } } } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ListByteBufferBinaryData.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ListByteBufferBinaryData.java index 778add767a70..1f751726619c 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ListByteBufferBinaryData.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/ListByteBufferBinaryData.java @@ -136,7 +136,7 @@ private byte[] getBytes() { } @Override - public void close() throws IOException { + public void close() { // no-op } } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/SerializableBinaryData.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/SerializableBinaryData.java index d253aab27a58..7188aa7b894c 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/SerializableBinaryData.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/SerializableBinaryData.java @@ -103,7 +103,7 @@ private byte[] getBytes() { } @Override - public void close() throws IOException { + public void close() { // no-op } } diff --git a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/StringBinaryData.java b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/StringBinaryData.java index e9ba9f96c5d0..2d4b83dfd621 100644 --- a/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/StringBinaryData.java +++ b/sdk/clientcore/core/src/main/java/io/clientcore/core/models/binarydata/StringBinaryData.java @@ -87,7 +87,7 @@ private byte[] getBytes() { } @Override - public void close() throws IOException { + public void close() { // no-op } } diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/RestProxyTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/RestProxyTests.java index 77e95436797c..9077cd62b5e2 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/RestProxyTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/RestProxyTests.java @@ -34,7 +34,6 @@ import org.junit.jupiter.params.provider.MethodSource; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.file.Files; @@ -101,7 +100,7 @@ Response> listNextFoo(@PathParam(value = "nextLink", encoded = true) S } @Test - public void contentTypeHeaderPriorityOverBodyParamAnnotationTest() throws IOException { + public void contentTypeHeaderPriorityOverBodyParamAnnotationTest() { HttpClient client = new LocalHttpClient(); HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(client).build(); @@ -222,7 +221,7 @@ public Response send(HttpRequest request) { return new MockHttpResponse(request, success ? 200 : 400) { @Override - public void close() throws IOException { + public void close() { closeCalledOnResponse = true; super.close(); @@ -236,7 +235,7 @@ public HttpRequest getLastHttpRequest() { } @Test - public void doesNotChangeEncodedPath() throws IOException { + public void doesNotChangeEncodedPath() { String nextLinkUri = "https://management.somecloud.com:443/subscriptions/000/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/vmss1/virtualMachines?api-version=2021-11-01&$skiptoken=Mzk4YzFjMzMtM2IwMC00OWViLWI2NGYtNjg4ZTRmZGQ1Nzc2IS9TdWJzY3JpcHRpb25zL2VjMGFhNWY3LTllNzgtNDBjOS04NWNkLTUzNWM2MzA1YjM4MC9SZXNvdXJjZUdyb3Vwcy9SRy1XRUlEWFUtVk1TUy9WTVNjYWxlU2V0cy9WTVNTMS9WTXMvNzc="; HttpPipeline pipeline = new HttpPipelineBuilder().httpClient((request) -> { diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/models/HttpResponseTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/models/HttpResponseTests.java index 8555b3cdd4b0..dec57fffb422 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/models/HttpResponseTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/models/HttpResponseTests.java @@ -42,7 +42,7 @@ public void constructor() throws IOException { } @Test - public void constructorWithNullValue() throws IOException { + public void constructorWithNullValue() { try (HttpResponse response = new HttpResponse<>(HTTP_REQUEST, STATUS_CODE, HEADERS, null)) { assertEquals(HTTP_REQUEST, response.getRequest()); assertEquals(STATUS_CODE, response.getStatusCode()); @@ -54,7 +54,7 @@ public void constructorWithNullValue() throws IOException { } @Test - public void constructorWithNullValueAndBodySet() throws IOException { + public void constructorWithNullValueAndBodySet() { try (HttpResponse response = new HttpResponse<>(HTTP_REQUEST, STATUS_CODE, HEADERS, null)) { assertEquals(HTTP_REQUEST, response.getRequest()); assertEquals(STATUS_CODE, response.getStatusCode()); @@ -69,7 +69,7 @@ public void constructorWithNullValueAndBodySet() throws IOException { } @Test - public void constructorWithNullValueBodySetAndBodyDeserializer() throws IOException { + public void constructorWithNullValueBodySetAndBodyDeserializer() { try (HttpResponse response = new HttpResponse<>(HTTP_REQUEST, STATUS_CODE, HEADERS, null)) { assertEquals(HTTP_REQUEST, response.getRequest()); assertEquals(STATUS_CODE, response.getStatusCode()); @@ -92,7 +92,7 @@ public void constructorWithNullValueBodySetAndBodyDeserializer() throws IOExcept } @Test - public void constructorWithValueDoesNotDeserializeBody() throws IOException { + public void constructorWithValueDoesNotDeserializeBody() { try (HttpResponse response = new HttpResponse<>(HTTP_REQUEST, STATUS_CODE, HEADERS, VALUE)) { assertEquals(HTTP_REQUEST, response.getRequest()); assertEquals(STATUS_CODE, response.getStatusCode()); diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/models/PagedResponseTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/models/PagedResponseTests.java index b643c434adab..288321b30e85 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/models/PagedResponseTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/models/PagedResponseTests.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.Collections; import java.util.List; @@ -49,8 +48,6 @@ public void testPagedResponseRequired() { Assertions.assertEquals(firstLink, pagedResponse.getFirstLink()); Assertions.assertEquals(lastLink, pagedResponse.getLastLink()); } - } catch (IOException e) { - Assertions.fail(); } } } diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpPipelinePolicyTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpPipelinePolicyTests.java index a6c6b62cee87..da70d5625a77 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpPipelinePolicyTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/HttpPipelinePolicyTests.java @@ -12,14 +12,13 @@ import io.clientcore.core.http.models.Response; import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import static org.junit.jupiter.api.Assertions.assertEquals; public class HttpPipelinePolicyTests { @Test - public void verifySend() throws IOException { + public void verifySend() { SyncPolicy policy1 = new SyncPolicy(); SyncPolicy policy2 = new SyncPolicy(); @@ -33,7 +32,7 @@ public void verifySend() throws IOException { } @Test - public void defaultImplementationShouldCallRightStack() throws IOException { + public void defaultImplementationShouldCallRightStack() { DefaultImplementationSyncPolicy policyWithDefaultSyncImplementation = new DefaultImplementationSyncPolicy(); HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(new NoOpHttpClient()) @@ -50,7 +49,7 @@ public void defaultImplementationShouldCallRightStack() throws IOException { * This is to cover case when reactor could complain about blocking on non-blocking thread. */ @Test - public void doesNotThrowThatThreadIsNonBlocking() throws IOException { + public void doesNotThrowThatThreadIsNonBlocking() { SyncPolicy policy1 = new SyncPolicy(); HttpPipelinePolicy badPolicy1 = (ignored, next) -> { try { diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/RetryPolicyTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/RetryPolicyTests.java index 6fb50f5b6774..7b761b407dc5 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/RetryPolicyTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/http/pipeline/RetryPolicyTests.java @@ -221,11 +221,11 @@ public Response send(HttpRequest request) { } @Test - public void retryConsumesBody() throws IOException { + public void retryConsumesBody() { AtomicInteger closeCalls = new AtomicInteger(); Response closeTrackingHttpResponse = new MockHttpResponse(null, 503, new HttpHeaders()) { @Override - public void close() throws IOException { + public void close() { closeCalls.incrementAndGet(); super.close(); } @@ -278,7 +278,7 @@ public void propagatingExceptionHasOtherErrorsAsSuppressedExceptions() { @ParameterizedTest @MethodSource("getWellKnownRetryDelaySupplier") - public void retryWellKnownRetryHeaders(HttpHeaders responseHeaders) throws IOException { + public void retryWellKnownRetryHeaders(HttpHeaders responseHeaders) { HttpRetryOptions retryOptions = new HttpRetryOptions(1, Duration.ofMillis(1)); AtomicInteger attemptCount = new AtomicInteger(); diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/implementation/http/rest/RestProxyImplTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/implementation/http/rest/RestProxyImplTests.java index 596612f5f022..cd629faae358 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/implementation/http/rest/RestProxyImplTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/implementation/http/rest/RestProxyImplTests.java @@ -97,7 +97,7 @@ public Response send(HttpRequest request) { return new MockHttpResponse(request, success ? 200 : 400) { @Override - public void close() throws IOException { + public void close() { lastResponseClosed = true; super.close(); diff --git a/sdk/clientcore/core/src/test/java/io/clientcore/core/implementation/serializer/HttpResponseBodyDecoderTests.java b/sdk/clientcore/core/src/test/java/io/clientcore/core/implementation/serializer/HttpResponseBodyDecoderTests.java index d0e8abc4f7b3..16acae269864 100644 --- a/sdk/clientcore/core/src/test/java/io/clientcore/core/implementation/serializer/HttpResponseBodyDecoderTests.java +++ b/sdk/clientcore/core/src/test/java/io/clientcore/core/implementation/serializer/HttpResponseBodyDecoderTests.java @@ -227,7 +227,7 @@ public void decodeListBase64UriResponse() { } @Test - public void malformedBodyReturnsError() throws IOException { + public void malformedBodyReturnsError() { try (Response response = new MockHttpResponse(GET_REQUEST, 200, (Object) null)) { HttpResponseDecodeData decodeData = new MockHttpResponseDecodeData(200, String.class, String.class, true); diff --git a/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpGet.java b/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpGet.java index 1ca540e259e4..29ce896f97b1 100644 --- a/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpGet.java +++ b/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpGet.java @@ -19,8 +19,6 @@ import io.clientcore.http.stress.util.TelemetryHelper; import reactor.core.publisher.Mono; -import java.io.IOException; -import java.io.UncheckedIOException; import java.net.URI; import java.net.URISyntaxException; import java.time.Instant; @@ -68,8 +66,6 @@ private void runInternal() { HttpRequest request = createRequest(); try (Response response = pipeline.send(request)) { response.getBody().toBytes(); - } catch (IOException e) { - LOGGER.logThrowableAsError(new UncheckedIOException(e)); } } @@ -97,13 +93,7 @@ private Mono runInternalAsync() { return Mono.usingWhen(Mono.fromCallable(() -> pipeline.send(createRequest())), response -> { response.getBody().toBytes(); return Mono.empty(); - }, response -> Mono.fromRunnable(() -> { - try { - response.close(); - } catch (IOException e) { - LOGGER.logThrowableAsError(new UncheckedIOException(e)); - } - })); + }, response -> Mono.fromRunnable(response::close)); } // Method to run using CompletableFuture diff --git a/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpPatch.java b/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpPatch.java index 6963f0f89845..a915a3575eda 100644 --- a/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpPatch.java +++ b/sdk/clientcore/http-stress/src/main/java/io/clientcore/http/stress/HttpPatch.java @@ -20,7 +20,6 @@ import io.clientcore.http.stress.util.TelemetryHelper; import reactor.core.publisher.Mono; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.time.Instant; @@ -64,8 +63,6 @@ private void runInternal() { int responseCode = response.getStatusCode(); assert responseCode == 200 : "Unexpected response code: " + responseCode; response.getBody().close(); - } catch (IOException e) { - throw LOGGER.logThrowableAsError(new RuntimeException(e)); } } diff --git a/sdk/clientcore/optional-dependency-tests/src/test/java/io/clientcore/core/instrumentation/SuppressionTests.java b/sdk/clientcore/optional-dependency-tests/src/test/java/io/clientcore/core/instrumentation/SuppressionTests.java index 307836b86f15..8c23a9a444fa 100644 --- a/sdk/clientcore/optional-dependency-tests/src/test/java/io/clientcore/core/instrumentation/SuppressionTests.java +++ b/sdk/clientcore/optional-dependency-tests/src/test/java/io/clientcore/core/instrumentation/SuppressionTests.java @@ -47,7 +47,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; public class SuppressionTests { private static final LibraryInstrumentationOptions DEFAULT_LIB_OPTIONS @@ -378,11 +377,7 @@ public void protocolMethod(RequestOptions options) { try (TracingScope scope = span.makeCurrent()) { Response response = pipeline.send(new HttpRequest().setMethod(HttpMethod.GET).setUri("https://localhost")); - try { - response.close(); - } catch (IOException e) { - fail(e); - } + response.close(); } finally { span.end(); } @@ -423,7 +418,7 @@ static class SampleClientCallInstrumentation { } @SuppressWarnings("try") - public void protocolMethod(RequestOptions options) throws IOException { + public void protocolMethod(RequestOptions options) { if (!protocolInstrumentation.shouldInstrument(options)) { Response response = pipeline.send(new HttpRequest().setMethod(HttpMethod.GET).setUri("https://localhost")); @@ -436,7 +431,7 @@ public void protocolMethod(RequestOptions options) throws IOException { Response response = pipeline.send(new HttpRequest().setMethod(HttpMethod.GET).setUri("https://localhost")); response.close(); - } catch (IOException e) { + } catch (RuntimeException e) { scope.setError(e); throw e; } finally { @@ -445,7 +440,7 @@ public void protocolMethod(RequestOptions options) throws IOException { } @SuppressWarnings("try") - public void convenienceMethod(RequestOptions options) throws IOException { + public void convenienceMethod(RequestOptions options) { if (!convenienceInstrumentation.shouldInstrument(options)) { protocolMethod(options); } @@ -453,7 +448,7 @@ public void convenienceMethod(RequestOptions options) throws IOException { OperationInstrumentation.Scope scope = convenienceInstrumentation.startScope(options); try { protocolMethod(options); - } catch (IOException e) { + } catch (RuntimeException e) { scope.setError(e); throw e; } finally {