From ed681f58e377caef73ec3fc7d6696704d4bbb62f Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Fri, 25 Oct 2024 10:18:13 -0700 Subject: [PATCH] move it all into 1 try block. --- oauth2_http/java/com/google/auth/oauth2/S2A.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/oauth2_http/java/com/google/auth/oauth2/S2A.java b/oauth2_http/java/com/google/auth/oauth2/S2A.java index 067eb4647..6f432f14f 100644 --- a/oauth2_http/java/com/google/auth/oauth2/S2A.java +++ b/oauth2_http/java/com/google/auth/oauth2/S2A.java @@ -137,9 +137,10 @@ private S2AConfig getS2AConfigFromMDS() { ServiceLoader.load(HttpTransportFactory.class), OAuth2Utils.HTTP_TRANSPORT_FACTORY); } - HttpRequest request; + String plaintextS2AAddress = ""; + String mtlsS2AAddress = ""; try { - request = transportFactory.create().createRequestFactory().buildGetRequest(genericUrl); + HttpRequest request = transportFactory.create().createRequestFactory().buildGetRequest(genericUrl); request.setParser(parser); request.getHeaders().set(METADATA_FLAVOR, GOOGLE); request.setThrowExceptionOnExecuteError(false); @@ -158,13 +159,7 @@ private S2AConfig getS2AConfigFromMDS() { .setBackOffRequired( response -> RETRYABLE_STATUS_CODES.contains(response.getStatusCode()))); request.setIOExceptionHandler(new HttpBackOffIOExceptionHandler(backoff)); - } catch (IOException e) { - return S2AConfig.createBuilder().build(); - } - String plaintextS2AAddress = ""; - String mtlsS2AAddress = ""; - try { HttpResponse response = request.execute(); InputStream content = response.getContent(); if (content == null) { @@ -186,6 +181,7 @@ private S2AConfig getS2AConfigFromMDS() { /* * Return empty addresses in {@link S2AConfig} once all retries have been exhausted. */ + return S2AConfig.createBuilder().build(); } return S2AConfig.createBuilder()