Skip to content

NPE in com.google.auth.oauth2.JwtCredentials$Builder.setPrivateKeyId(JwtCredentials.java:223) due to a mistake in io.grpc.auth.GoogleAuthLibraryCallCredentials #6105

@Alxbss

Description

@Alxbss

Hi All,
I run an application that uses java clients libraries for pubsub, stackdriver logging, stackdriver tracing.
Everything works ok, if the application uses only pubsub or stackdriver logging & tracing, but if it uses all of them then I got a NPE.

I debugged the application and it seems like I found the root cause.
There is the following class:

Method getter = serviceAccountClass.getMethod("getPrivateKey");

with these lines:
{
Method getter = serviceAccountClass.getMethod("getPrivateKey");
Method setter = builderClass.getMethod("setPrivateKey", getter.getReturnType());
methodPairs.add(new MethodPair(getter, setter));
}
{
Method getter = serviceAccountClass.getMethod("getPrivateKey");
Method setter = builderClass.getMethod("setPrivateKey", getter.getReturnType());
methodPairs.add(new MethodPair(getter, setter));
}

It seems like a copy-paste mistake that was introduced in this commit:
09d9c4a

I think it must be like:
{
Method getter = serviceAccountClass.getMethod("getPrivateKey");
Method setter = builderClass.getMethod("setPrivateKey", getter.getReturnType());
methodPairs.add(new MethodPair(getter, setter));
}
{
Method getter = serviceAccountClass.getMethod("getPrivateKeyId");
Method setter = builderClass.getMethod("setPrivateKeyId", getter.getReturnType());
methodPairs.add(new MethodPair(getter, setter));
}

The stacktrace of the issue:

18:44:39.562 [ExportComponent.ServiceExporterThread-0] WARN i.o.trace.export.ExportComponent - Exception thrown by the service export io.opencensus.exporter.trace.stackdriver.StackdriverTraceExporter com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:73) at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72) at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60) at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97) at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:68) at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:982) at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30) at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1138) at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:957) at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:748) at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:515) at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:490) at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:700) at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:399) at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:510) at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:66) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:630) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:518) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:692) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:681) at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57) at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112) at com.google.cloud.trace.v2.TraceServiceClient.batchWriteSpans(TraceServiceClient.java:234) at com.google.cloud.trace.v2.TraceServiceClient.batchWriteSpans(TraceServiceClient.java:182) at io.opencensus.exporter.trace.stackdriver.StackdriverV2ExporterHandler.export(StackdriverV2ExporterHandler.java:444) at io.opencensus.implcore.trace.export.SpanExporterImpl$Worker.onBatchExport(SpanExporterImpl.java:248) at io.opencensus.implcore.trace.export.SpanExporterImpl$Worker.exportBatches(SpanExporterImpl.java:350) at io.opencensus.implcore.trace.export.SpanExporterImpl$Worker.run(SpanExporterImpl.java:290) ... 1 common frames omitted Caused by: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata at io.grpc.Status.asRuntimeException(Status.java:533) ... 24 common frames omitted Caused by: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2049) at com.google.common.cache.LocalCache.get(LocalCache.java:3851) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3875) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4800) at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.getRequestMetadata(ServiceAccountJwtAccessCredentials.java:346) at com.google.auth.Credentials.blockingGetToCallback(Credentials.java:112) at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.getRequestMetadata(ServiceAccountJwtAccessCredentials.java:323) at io.grpc.auth.GoogleAuthLibraryCallCredentials.applyRequestMetadata(GoogleAuthLibraryCallCredentials.java:110) at io.grpc.CallCredentials2.applyRequestMetadata(CallCredentials2.java:58) at io.grpc.internal.CallCredentialsApplyingTransportFactory$CallCredentialsApplyingTransport.newStream(CallCredentialsApplyingTransportFactory.java:108) at io.grpc.internal.ForwardingConnectionClientTransport.newStream(ForwardingConnectionClientTransport.java:49) at io.grpc.internal.InternalSubchannel$CallTracingTransport.newStream(InternalSubchannel.java:632) at io.grpc.internal.DelayedClientTransport$PendingStream.createRealStream(DelayedClientTransport.java:353) at io.grpc.internal.DelayedClientTransport$PendingStream.access$300(DelayedClientTransport.java:341) at io.grpc.internal.DelayedClientTransport$5.run(DelayedClientTransport.java:300) ... 7 common frames omitted Caused by: java.lang.NullPointerException: null at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:890) at com.google.auth.oauth2.JwtCredentials$Builder.setPrivateKeyId(JwtCredentials.java:223) at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials$1.load(ServiceAccountJwtAccessCredentials.java:271) at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials$1.load(ServiceAccountJwtAccessCredentials.java:266) at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3445) at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2194) at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2153) at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2043) ... 21 common frames omitted 

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions