Skip to content

Commit c3529a4

Browse files
committed
fix credentials NPE bug #1565
1 parent fb68318 commit c3529a4

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
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;
2322

2423
import com.google.api.core.ApiClock;
2524
import com.google.api.core.CurrentMillisClock;
@@ -37,12 +36,9 @@
3736
import java.io.FileReader;
3837
import java.io.IOException;
3938
import java.io.InputStream;
40-
import java.io.InputStreamReader;
4139
import java.io.ObjectInputStream;
4240
import java.io.Serializable;
4341
import java.lang.reflect.Method;
44-
import java.net.HttpURLConnection;
45-
import java.net.URL;
4642
import java.nio.charset.Charset;
4743
import java.util.Locale;
4844
import java.util.Objects;
@@ -461,6 +457,17 @@ public Credentials getCredentials() {
461457
return credentials;
462458
}
463459

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+
464471
/**
465472
* Returns the authentication credentials. If required, credentials are scoped.
466473
*/

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
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;
3231
import com.google.cloud.logging.LoggingException;
3332
import com.google.cloud.logging.LoggingOptions;
3433
import com.google.logging.v2.CreateLogMetricRequest;
@@ -82,7 +81,7 @@ public GrpcLoggingRpc(LoggingOptions options) throws IOException {
8281
ChannelProvider channelProvider;
8382
// todo(mziccard): ChannelProvider should support null/absent credentials for testing
8483
if (options.getHost().contains("localhost")
85-
|| options.getCredentials().equals(NoCredentials.getInstance())) {
84+
|| options.credentialIsNoCredentialInstance()) {
8685
ManagedChannel managedChannel = ManagedChannelBuilder.forTarget(options.getHost())
8786
.usePlaintext(true)
8887
.executor(executor)

0 commit comments

Comments
 (0)