google-cloud-java icon indicating copy to clipboard operation
google-cloud-java copied to clipboard

ServiceOptions.getCredentials can return null and cause NPE in Logging and PubSub

Open vkedia opened this issue 9 years ago • 2 comments

In ServiceOptions.java is no credentials are explicitly specified, it would default to calling getApplicationDefault here: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java#L312

But that method can fail by throwing an exception if for eg the credentials file is missing. In that case ServiceOptions just catches the exception, ignores it and returns null: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java#L314

But reading the documentation on getCredentials, it is not clear that callers should be handling null return value. google-cloud-java seems to be not handling the null return value atleast in couple of places: https://github.com/GoogleCloudPlatform/google-cloud-java/blob/00add6e26fc2e1a533b715df28a5568222483f65/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/DefaultLoggingRpc.java#L117 https://github.com/GoogleCloudPlatform/google-cloud-java/blob/00add6e26fc2e1a533b715df28a5568222483f65/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/DefaultPubSubRpc.java#L146

vkedia avatar Jan 25 '17 23:01 vkedia

Re-opening because:

  • #1955 was rolled back because integration tests failed
  • #1955 only fixed Logging, not the rest of the APIs

garrettjonesgoogle avatar Apr 21 '17 13:04 garrettjonesgoogle

WIth this fix (#1961) the NPE error for Logging should be fixed. New Pubsub shouldn't have this issue.

neozwu avatar Apr 24 '17 16:04 neozwu