Skip to content

Commit 3f2d3a2

Browse files
committed
fix options.getCredentials() NPE
1 parent de224fb commit 3f2d3a2

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.MoreObjects.firstNonNull;
2020
import static com.google.common.base.Preconditions.checkArgument;
2121
import static com.google.common.base.Preconditions.checkNotNull;
22+
import static java.nio.charset.StandardCharsets.UTF_8;
2223

2324
import com.google.api.core.ApiClock;
2425
import com.google.api.core.CurrentMillisClock;
@@ -36,9 +37,12 @@
3637
import java.io.FileReader;
3738
import java.io.IOException;
3839
import java.io.InputStream;
40+
import java.io.InputStreamReader;
3941
import java.io.ObjectInputStream;
4042
import java.io.Serializable;
4143
import java.lang.reflect.Method;
44+
import java.net.HttpURLConnection;
45+
import java.net.URL;
4246
import java.nio.charset.Charset;
4347
import java.util.Locale;
4448
import java.util.Objects;
@@ -457,17 +461,6 @@ public Credentials getCredentials() {
457461
return credentials;
458462
}
459463

460-
/**
461-
* Returns whether the credential is {@code NoCredentials} instance
462-
* @return true if credential is a {@code NoCredentials} instance, false if not
463-
*/
464-
public boolean credentialIsNoCredentialInstance() {
465-
if (credentials != null) {
466-
return credentials.equals(NoCredentials.getInstance());
467-
}
468-
return false;
469-
}
470-
471464
/**
472465
* Returns the authentication credentials. If required, credentials are scoped.
473466
*/

google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/GrpcLoggingRpc.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.api.gax.grpc.UnaryCallSettings;
2929
import com.google.cloud.GrpcTransportOptions;
3030
import com.google.cloud.GrpcTransportOptions.ExecutorFactory;
31+
import com.google.cloud.NoCredentials;
3132
import com.google.cloud.logging.LoggingException;
3233
import com.google.cloud.logging.LoggingOptions;
3334
import com.google.logging.v2.CreateLogMetricRequest;
@@ -81,11 +82,12 @@ public GrpcLoggingRpc(LoggingOptions options) throws IOException {
8182
ChannelProvider channelProvider;
8283
// todo(mziccard): ChannelProvider should support null/absent credentials for testing
8384
if (options.getHost().contains("localhost")
84-
|| options.credentialIsNoCredentialInstance()) {
85-
ManagedChannel managedChannel = ManagedChannelBuilder.forTarget(options.getHost())
86-
.usePlaintext(true)
87-
.executor(executor)
88-
.build();
85+
|| NoCredentials.getInstance().equals(options.getCredentials())) {
86+
ManagedChannel managedChannel =
87+
ManagedChannelBuilder.forTarget(options.getHost())
88+
.usePlaintext(true)
89+
.executor(executor)
90+
.build();
8991
channelProvider = FixedChannelProvider.create(managedChannel);
9092
} else {
9193
channelProvider = GrpcTransportOptions.setUpChannelProvider(

0 commit comments

Comments
 (0)