Skip to content

Commit 33d6e45

Browse files
authored
Merge branch 'main' into cherry-pick-java-spanner-jdbc
2 parents b20b3cc + 92bcdf4 commit 33d6e45

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

.github/workflows/sdk-platform-java-nightly.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: |
4949
gh issue create \
5050
--title "Nightly build for Java ${{ matrix.java }} on ${{ matrix.os }} failed." \
51-
--body "The build has failed : https://github.com/googleapis/gapic-generator-java/actions/runs/${GITHUB_RUN_ID}"
51+
--body "The build has failed : https://github.com/googleapis/google-cloud-java/actions/runs/${GITHUB_RUN_ID}"
5252
nightly-java8: # Compile with JDK 11. Run tests with JDK 8.
5353
needs: filter
5454
if: ${{ needs.filter.outputs.library == 'true' }}

sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)