File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
sdk-platform-java/gax-java/gax/src
main/java/com/google/api/gax/rpc
test/java/com/google/api/gax/rpc Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ public static EndpointContext getDefaultInstance() {
134134
135135 public abstract String resolvedEndpoint ();
136136
137+ @ Nullable
137138 public abstract String resolvedServerAddress ();
138139
139140 @ Nullable
@@ -410,7 +411,7 @@ private Integer parseServerPort(String endpoint) {
410411 return null ;
411412 }
412413 HostAndPort hostAndPort = parseServerHostAndPort (endpoint );
413- if (!hostAndPort .hasPort ()) {
414+ if (hostAndPort == null || !hostAndPort .hasPort ()) {
414415 return null ;
415416 }
416417 return hostAndPort .getPort ();
@@ -466,8 +467,13 @@ public EndpointContext build() throws IOException {
466467 setResolvedUniverseDomain (determineUniverseDomain ());
467468 String endpoint = determineEndpoint ();
468469 setResolvedEndpoint (endpoint );
469- setResolvedServerAddress (parseServerAddress (resolvedEndpoint ()));
470- setResolvedServerPort (parseServerPort (resolvedEndpoint ()));
470+ try {
471+ setResolvedServerAddress (parseServerAddress (resolvedEndpoint ()));
472+ setResolvedServerPort (parseServerPort (resolvedEndpoint ()));
473+ } catch (Exception throwable ) {
474+ // Server address and server port are only used for observability.
475+ // We should ignore any errors parsing them and not affect the main client requests.
476+ }
471477 setUseS2A (shouldUseS2A ());
472478 return autoBuild ();
473479 }
Original file line number Diff line number Diff line change @@ -683,4 +683,19 @@ void endpointContextBuild_resolvesPort() throws IOException {
683683 .build ();
684684 Truth .assertThat (endpointContext .resolvedServerPort ()).isNull ();
685685 }
686+
687+ @ Test
688+ void endpointContextBuild_resolvesInvalidEndpointAndPort () throws Exception {
689+
690+ String endpoint = "localhost:-1" ;
691+
692+ EndpointContext endpointContext =
693+ defaultEndpointContextBuilder
694+ .setClientSettingsEndpoint (endpoint )
695+ .setTransportChannelProviderEndpoint (null )
696+ .build ();
697+
698+ Truth .assertThat (endpointContext .resolvedServerAddress ()).isNull ();
699+ Truth .assertThat (endpointContext .resolvedServerPort ()).isNull ();
700+ }
686701}
You can’t perform that action at this time.
0 commit comments