From feac5e5627a74fb086238f62edddaebcfdaa96d3 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Mon, 28 Apr 2025 17:55:28 -0400 Subject: [PATCH 1/5] fix: Only send mtlsEndpoint if it is non-null --- .../gax/src/main/java/com/google/api/gax/rpc/ClientContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java index 247e2f10f9..164b41b96a 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java @@ -223,7 +223,7 @@ public static ClientContext create(StubSettings settings) throws IOException { transportChannelProvider = transportChannelProvider.withEndpoint(endpoint); } transportChannelProvider = transportChannelProvider.withUseS2A(endpointContext.useS2A()); - if (transportChannelProvider.needsMtlsEndpoint()) { + if (transportChannelProvider.needsMtlsEndpoint() && endpointContext.mtlsEndpoint() != null) { transportChannelProvider = transportChannelProvider.withMtlsEndpoint(endpointContext.mtlsEndpoint()); } From a88b88121c809fae1859c0a7aa2f3b2ad882a408 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Fri, 2 May 2025 14:51:59 -0400 Subject: [PATCH 2/5] chore: Add tests for a the mtlsEndpoint check --- .../google/api/gax/rpc/ClientContextTest.java | 167 +++++++++++++----- 1 file changed, 127 insertions(+), 40 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index 826864a49c..a737f3c51a 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -70,11 +70,13 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import org.junit.jupiter.api.Test; +import org.junit.platform.commons.util.Preconditions; import org.mockito.Mockito; class ClientContextTest { - private static final String DEFAULT_ENDPOINT = "test.googleapis.com"; private static final String DEFAULT_UNIVERSE_DOMAIN = "googleapis.com"; + private static final String DEFAULT_ENDPOINT = "https://foo.googleapis.com"; + private static final String DEFAULT_MTLS_ENDPOINT = "https://foo.mtls.googleapis.com"; private static class InterceptingExecutor extends ScheduledThreadPoolExecutor { boolean shutdownCalled = false; @@ -115,6 +117,7 @@ private static class FakeTransportProvider implements TransportChannelProvider { final Map headers; final Credentials credentials; final String endpoint; + final String mtlsEndpoint; FakeTransportProvider( FakeTransportChannel transport, @@ -122,7 +125,8 @@ private static class FakeTransportProvider implements TransportChannelProvider { boolean shouldAutoClose, Map headers, Credentials credentials, - String endpoint) { + String endpoint, + String mtlsEndpoint) { this.transport = transport; this.executor = executor; this.shouldAutoClose = shouldAutoClose; @@ -130,6 +134,7 @@ private static class FakeTransportProvider implements TransportChannelProvider { this.transport.setHeaders(headers); this.credentials = credentials; this.endpoint = endpoint; + this.mtlsEndpoint = mtlsEndpoint; } @Override @@ -155,7 +160,8 @@ public TransportChannelProvider withExecutor(Executor executor) { this.shouldAutoClose, this.headers, this.credentials, - this.endpoint); + this.endpoint, + this.mtlsEndpoint); } @Override @@ -171,7 +177,8 @@ public TransportChannelProvider withHeaders(Map headers) { this.shouldAutoClose, headers, this.credentials, - this.endpoint); + this.endpoint, + this.mtlsEndpoint); } @Override @@ -192,7 +199,8 @@ public TransportChannelProvider withEndpoint(String endpoint) { this.shouldAutoClose, this.headers, this.credentials, - endpoint); + endpoint, + this.mtlsEndpoint); } @Override @@ -230,7 +238,28 @@ public TransportChannelProvider withCredentials(Credentials credentials) { this.shouldAutoClose, this.headers, credentials, - this.endpoint); + this.endpoint, + this.mtlsEndpoint); + } + + @Override + public boolean needsMtlsEndpoint() { + return this.mtlsEndpoint == null; + } + + @Override + public TransportChannelProvider withMtlsEndpoint(String mtlsEndpoint) { + // Throws NPE if this is passed with a null value. This should never happen as + // GAPICs should always have a default mtlsEndpoint value + Preconditions.notNull(mtlsEndpoint, "mtlsEndpoint should never be null"); + return new FakeTransportProvider( + this.transport, + this.executor, + this.shouldAutoClose, + this.headers, + this.credentials, + this.endpoint, + mtlsEndpoint); } } @@ -278,7 +307,8 @@ private void runTest( shouldAutoClose, needHeaders ? null : headers, null, - DEFAULT_ENDPOINT); + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); Credentials credentials = Mockito.mock(Credentials.class); ApiClock clock = Mockito.mock(ApiClock.class); Watchdog watchdog = @@ -352,7 +382,8 @@ void testWatchdogProvider() throws IOException { InterceptingExecutor executor = new InterceptingExecutor(1); FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = - new FakeTransportProvider(transportChannel, executor, true, null, null, DEFAULT_ENDPOINT); + new FakeTransportProvider( + transportChannel, executor, true, null, null, DEFAULT_ENDPOINT, DEFAULT_MTLS_ENDPOINT); ApiClock clock = Mockito.mock(ApiClock.class); builder.setClock(clock); @@ -391,7 +422,8 @@ void testMergeHeaders_getQuotaProjectIdFromHeadersProvider() throws IOException InterceptingExecutor executor = new InterceptingExecutor(1); FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = - new FakeTransportProvider(transportChannel, executor, true, null, null, DEFAULT_ENDPOINT); + new FakeTransportProvider( + transportChannel, executor, true, null, null, DEFAULT_ENDPOINT, DEFAULT_MTLS_ENDPOINT); HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class); Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of("header_k1", "v1")); @@ -427,7 +459,8 @@ void testMergeHeaders_getQuotaProjectIdFromSettings() throws IOException { InterceptingExecutor executor = new InterceptingExecutor(1); FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = - new FakeTransportProvider(transportChannel, executor, true, null, null, DEFAULT_ENDPOINT); + new FakeTransportProvider( + transportChannel, executor, true, null, null, DEFAULT_ENDPOINT, DEFAULT_MTLS_ENDPOINT); HeaderProvider headerProvider = new HeaderProvider() { @@ -473,7 +506,8 @@ void testMergeHeaders_noQuotaProjectIdSet() throws IOException { InterceptingExecutor executor = new InterceptingExecutor(1); FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = - new FakeTransportProvider(transportChannel, executor, true, null, null, DEFAULT_ENDPOINT); + new FakeTransportProvider( + transportChannel, executor, true, null, null, DEFAULT_ENDPOINT, DEFAULT_MTLS_ENDPOINT); HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class); Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of("header_k1", "v1")); @@ -504,7 +538,8 @@ void testHidingQuotaProjectId_quotaSetFromSetting() throws IOException { InterceptingExecutor executor = new InterceptingExecutor(1); FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = - new FakeTransportProvider(transportChannel, executor, true, null, null, DEFAULT_ENDPOINT); + new FakeTransportProvider( + transportChannel, executor, true, null, null, DEFAULT_ENDPOINT, DEFAULT_MTLS_ENDPOINT); Map> metaDataWithQuota = ImmutableMap.of( "k1", @@ -545,7 +580,8 @@ void testHidingQuotaProjectId_noQuotaSetFromSetting() throws IOException { InterceptingExecutor executor = new InterceptingExecutor(1); FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = - new FakeTransportProvider(transportChannel, executor, true, null, null, DEFAULT_ENDPOINT); + new FakeTransportProvider( + transportChannel, executor, true, null, null, DEFAULT_ENDPOINT, DEFAULT_MTLS_ENDPOINT); Map> metaData = ImmutableMap.of("k1", Collections.singletonList("v1")); final Credentials credentialsWithoutQuotaProjectId = Mockito.mock(GoogleCredentials.class); Mockito.when(credentialsWithoutQuotaProjectId.getRequestMetadata(null)).thenReturn(metaData); @@ -581,7 +617,8 @@ void testQuotaProjectId_worksWithNullCredentials() throws IOException { true, null, Mockito.mock(Credentials.class), - DEFAULT_ENDPOINT); + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); final FakeClientSettings.Builder settingsBuilder = new FakeClientSettings.Builder(); @@ -602,7 +639,8 @@ void testUserAgentInternalOnly() throws Exception { true, null, null, - DEFAULT_ENDPOINT); + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); ClientSettings.Builder builder = new FakeClientSettings.Builder() @@ -630,7 +668,8 @@ void testUserAgentExternalOnly() throws Exception { true, null, null, - DEFAULT_ENDPOINT); + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); ClientSettings.Builder builder = new FakeClientSettings.Builder() @@ -658,7 +697,8 @@ void testUserAgentConcat() throws Exception { true, null, null, - DEFAULT_ENDPOINT); + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); ClientSettings.Builder builder = new FakeClientSettings.Builder() @@ -743,7 +783,8 @@ private Map setupTestForCredentialTokenUsageMetricsAndGetTranspo true, null, null, - DEFAULT_ENDPOINT); + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); ClientSettings.Builder builder = new FakeClientSettings.Builder() @@ -759,31 +800,28 @@ private Map setupTestForCredentialTokenUsageMetricsAndGetTranspo return transportChannel.getHeaders(); } - private static String endpoint = "https://foo.googleapis.com"; - private static String mtlsEndpoint = "https://foo.mtls.googleapis.com"; - @Test void testSwitchToMtlsEndpointAllowed() throws IOException { - StubSettings settings = new FakeStubSettings.Builder().setEndpoint(endpoint).build(); + StubSettings settings = new FakeStubSettings.Builder().setEndpoint(DEFAULT_ENDPOINT).build(); assertFalse(settings.getSwitchToMtlsEndpointAllowed()); - assertEquals(endpoint, settings.getEndpoint()); + assertEquals(DEFAULT_ENDPOINT, settings.getEndpoint()); settings = new FakeStubSettings.Builder() - .setEndpoint(endpoint) + .setEndpoint(DEFAULT_ENDPOINT) .setSwitchToMtlsEndpointAllowed(true) .build(); assertTrue(settings.getSwitchToMtlsEndpointAllowed()); - assertEquals(endpoint, settings.getEndpoint()); + assertEquals(DEFAULT_ENDPOINT, settings.getEndpoint()); // Test setEndpoint sets the switchToMtlsEndpointAllowed value to false. settings = new FakeStubSettings.Builder() .setSwitchToMtlsEndpointAllowed(true) - .setEndpoint(endpoint) + .setEndpoint(DEFAULT_ENDPOINT) .build(); assertFalse(settings.getSwitchToMtlsEndpointAllowed()); - assertEquals(endpoint, settings.getEndpoint()); + assertEquals(DEFAULT_ENDPOINT, settings.getEndpoint()); } @Test @@ -795,7 +833,8 @@ void testExecutorSettings() throws Exception { true, null, null, - DEFAULT_ENDPOINT); + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); ClientSettings.Builder builder = new FakeClientSettings.Builder() @@ -842,7 +881,8 @@ void testExecutorSettings() throws Exception { true, null, null, - DEFAULT_ENDPOINT)); + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT)); context = ClientContext.create(builder.build()); transportChannel = (FakeTransportChannel) context.getTransportChannel(); assertThat(transportChannel.getExecutor()).isSameInstanceAs(executorProvider.getExecutor()); @@ -864,7 +904,13 @@ private GdchCredentials getMockGdchCredentials() throws IOException { private TransportChannelProvider getFakeTransportChannelProvider() { return new FakeTransportProvider( - FakeTransportChannel.create(new FakeChannel()), null, true, null, null, DEFAULT_ENDPOINT); + FakeTransportChannel.create(new FakeChannel()), + null, + true, + null, + null, + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); } // EndpointContext will construct a valid endpoint if nothing is provided @@ -872,7 +918,7 @@ private TransportChannelProvider getFakeTransportChannelProvider() { void testCreateClientContext_withGdchCredentialNoAudienceNoEndpoint() throws IOException { TransportChannelProvider transportChannelProvider = new FakeTransportProvider( - FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null); + FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); Credentials creds = getMockGdchCredentials(); CredentialsProvider provider = FixedCredentialsProvider.create(creds); @@ -899,7 +945,7 @@ void testCreateClientContext_withGdchCredentialNoAudienceEmptyEndpoint_throws() throws IOException { TransportChannelProvider transportChannelProvider = new FakeTransportProvider( - FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null); + FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); Credentials creds = getMockGdchCredentials(); CredentialsProvider provider = FixedCredentialsProvider.create(creds); @@ -922,7 +968,7 @@ void testCreateClientContext_withGdchCredentialWithoutAudienceWithEndpoint_corre throws IOException { TransportChannelProvider transportChannelProvider = new FakeTransportProvider( - FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null); + FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); Credentials creds = getMockGdchCredentials(); // it should correctly create a client context with gdch creds and null audience @@ -1034,7 +1080,7 @@ void testCreateClientContext_withNonGdchCredentialAndAnyAudience_throws() throws void testCreateClientContext_SetEndpointViaClientSettings() throws IOException { TransportChannelProvider transportChannelProvider = new FakeTransportProvider( - FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null); + FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); StubSettings settings = new FakeStubSettings.Builder() .setEndpoint(DEFAULT_ENDPOINT) @@ -1060,7 +1106,8 @@ void testCreateClientContext_SetEndpointViaTransportChannelProvider() throws IOE true, null, null, - transportChannelProviderEndpoint); + transportChannelProviderEndpoint, + DEFAULT_MTLS_ENDPOINT); StubSettings settings = new FakeStubSettings.Builder() .setEndpoint(null) @@ -1088,7 +1135,8 @@ void testCreateClientContext_SetEndpointViaClientSettingsAndTransportChannelProv true, null, null, - transportChannelProviderEndpoint); + transportChannelProviderEndpoint, + DEFAULT_MTLS_ENDPOINT); StubSettings settings = new FakeStubSettings.Builder() .setEndpoint(clientSettingsEndpoint) @@ -1111,7 +1159,7 @@ void testCreateClientContext_SetEndpointViaClientSettingsAndTransportChannelProv void testCreateClientContext_doNotSetUniverseDomain() throws IOException { TransportChannelProvider transportChannelProvider = new FakeTransportProvider( - FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null); + FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); StubSettings settings = new FakeStubSettings.Builder() .setEndpoint(null) @@ -1130,7 +1178,7 @@ void testCreateClientContext_doNotSetUniverseDomain() throws IOException { void testCreateClientContext_setUniverseDomain() throws IOException { TransportChannelProvider transportChannelProvider = new FakeTransportProvider( - FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null); + FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); String universeDomain = "testdomain.com"; StubSettings settings = new FakeStubSettings.Builder().setEndpoint(null).setUniverseDomain(universeDomain).build(); @@ -1163,7 +1211,13 @@ void testSetApiKey_createsApiCredentials() throws IOException { FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = new FakeTransportProvider( - transportChannel, executor, true, ImmutableMap.of(), null, DEFAULT_ENDPOINT); + transportChannel, + executor, + true, + ImmutableMap.of(), + null, + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); builder.setTransportChannelProvider(transportProvider); HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class); Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of()); @@ -1184,7 +1238,13 @@ void testSetApiKey_withDefaultCredentials_overridesCredentials() throws IOExcept FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel()); FakeTransportProvider transportProvider = new FakeTransportProvider( - transportChannel, executor, true, ImmutableMap.of(), null, DEFAULT_ENDPOINT); + transportChannel, + executor, + true, + ImmutableMap.of(), + null, + DEFAULT_ENDPOINT, + DEFAULT_MTLS_ENDPOINT); builder.setTransportChannelProvider(transportProvider); HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class); Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of()); @@ -1196,4 +1256,31 @@ void testSetApiKey_withDefaultCredentials_overridesCredentials() throws IOExcept FakeCallContext fakeCallContext = (FakeCallContext) context.getDefaultCallContext(); assertThat(fakeCallContext.getCredentials()).isInstanceOf(ApiKeyCredentials.class); } + + // This test case is added to cover a special case with BigTable. BigTable's EnhancedStubSettings + // wrappers do not directly inherit from the generated StubSettings. The wrappers must directly + // set the endpoint values since they are set in the generated StubSettings. This test case mimics + // the old behavior where BigTable doesn't set an mtlsEndpoint value. + @Test + void test_nullMtlsEndpointIsNotPassedToTransportChannel() throws IOException { + TransportChannelProvider transportChannelProvider = + new FakeTransportProvider( + FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); + // TransportChannelProvider would try to get the resolved mtlsEndpoint + Truth.assertThat(transportChannelProvider.needsMtlsEndpoint()).isTrue(); + + StubSettings settings = + new FakeStubSettings.Builder() + .setEndpoint(DEFAULT_ENDPOINT) + // Set this to be null so that the resolved mtls endpoint is null + .setMtlsEndpoint(null) + .build(); + ClientSettings.Builder clientSettingsBuilder = new FakeClientSettings.Builder(settings); + clientSettingsBuilder.setTransportChannelProvider(transportChannelProvider); + ClientSettings clientSettings = clientSettingsBuilder.build(); + + // This call should not result in an exception being thrown as a null resolved mtlsEndpoint + // is not passed to the TransportChannelProvider + ClientContext.create(clientSettings); + } } From d812dc8e8cf51f14ce81eee9974b0977afc8d27f Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Fri, 2 May 2025 14:54:31 -0400 Subject: [PATCH 3/5] chore: Add tests for a the mtlsEndpoint check --- .../test/java/com/google/api/gax/rpc/ClientContextTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index a737f3c51a..fcd9057d99 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -1263,6 +1263,9 @@ void testSetApiKey_withDefaultCredentials_overridesCredentials() throws IOExcept // the old behavior where BigTable doesn't set an mtlsEndpoint value. @Test void test_nullMtlsEndpointIsNotPassedToTransportChannel() throws IOException { + // Set the mtlsEndpoint in the TransportChannelProvider as null. This configures the + // ClientContext + // to attempt to pass the mtlsEndpoint over. TransportChannelProvider transportChannelProvider = new FakeTransportProvider( FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); From 5e9533cf8c0353743548da2e53bfce89486c450b Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Fri, 2 May 2025 14:55:46 -0400 Subject: [PATCH 4/5] chore: Add tests for a the mtlsEndpoint check --- .../test/java/com/google/api/gax/rpc/ClientContextTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index fcd9057d99..dd5dcd85fc 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -1264,8 +1264,7 @@ void testSetApiKey_withDefaultCredentials_overridesCredentials() throws IOExcept @Test void test_nullMtlsEndpointIsNotPassedToTransportChannel() throws IOException { // Set the mtlsEndpoint in the TransportChannelProvider as null. This configures the - // ClientContext - // to attempt to pass the mtlsEndpoint over. + // ClientContext to attempt to pass the mtlsEndpoint over. TransportChannelProvider transportChannelProvider = new FakeTransportProvider( FakeTransportChannel.create(new FakeChannel()), null, true, null, null, null, null); @@ -1276,6 +1275,7 @@ void test_nullMtlsEndpointIsNotPassedToTransportChannel() throws IOException { new FakeStubSettings.Builder() .setEndpoint(DEFAULT_ENDPOINT) // Set this to be null so that the resolved mtls endpoint is null + // This resolved value should not be passed to the TransportChannelProvider .setMtlsEndpoint(null) .build(); ClientSettings.Builder clientSettingsBuilder = new FakeClientSettings.Builder(settings); From 499314533ce4328b1bd9df855568860449bacb56 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Fri, 2 May 2025 15:11:39 -0400 Subject: [PATCH 5/5] chore: Manually throw exception for null mtlsEndpoint --- .../java/com/google/api/gax/rpc/ClientContextTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java index dd5dcd85fc..c7a6731d03 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java @@ -70,7 +70,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import org.junit.jupiter.api.Test; -import org.junit.platform.commons.util.Preconditions; import org.mockito.Mockito; class ClientContextTest { @@ -249,9 +248,11 @@ public boolean needsMtlsEndpoint() { @Override public TransportChannelProvider withMtlsEndpoint(String mtlsEndpoint) { - // Throws NPE if this is passed with a null value. This should never happen as - // GAPICs should always have a default mtlsEndpoint value - Preconditions.notNull(mtlsEndpoint, "mtlsEndpoint should never be null"); + // Throws an exception if this is passed with a null value. This should never + // happen as GAPICs should always have a default mtlsEndpoint value + if (mtlsEndpoint == null) { + throw new IllegalArgumentException("mtlsEndpoint is null"); + } return new FakeTransportProvider( this.transport, this.executor,