Skip to content

java.lang.NoSuchMethodException: com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.<init>(java.lang.String, java.lang.String, java.security.PrivateKey, java.lang.String) #4946

Closed

Description

@laurentpellegrino

Environment details

Initializing a pubsub client from a service account is broken (Java client version 1.69.0).

The issue was encountered on Fedora using Java 11.

Steps to reproduce

  1. Create a service account with role pubsub editor.
  2. Create a publisher with credentials loading the service account created in the previous step.

Code example

BufferedInputStream serviceAccount =
    new BufferedInputStream(getClass().getResourceAsStream(
        "/keyfiles/my-project-publisher.json"));

ProjectTopicName topicName = ProjectTopicName.of("my-project", "usage");

GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);

publisher =
    Publisher.newBuilder(topicName)
        .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
        .setBatchingSettings(
            BatchingSettings.newBuilder()
                 .setDelayThreshold(Duration.ofMillis(500))
                 .setElementCountThreshold(1000L).build())
    .build();

Stack trace

java.lang.NoSuchMethodException: com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.<init>(java.lang.String, java.lang.String, java.security.PrivateKey, java.lang.String)
	at java.base/java.lang.Class.getConstructor0(Class.java:3350) ~[na:na]
	at java.base/java.lang.Class.getConstructor(Class.java:2152) ~[na:na]
	at io.grpc.auth.GoogleAuthLibraryCallCredentials$JwtHelper.<init>(GoogleAuthLibraryCallCredentials.java:270) ~[grpc-auth-1.19.0.jar:1.19.0]
	at io.grpc.auth.GoogleAuthLibraryCallCredentials.createJwtHelperOrNull(GoogleAuthLibraryCallCredentials.java:221) ~[grpc-auth-1.19.0.jar:1.19.0]
	at io.grpc.auth.GoogleAuthLibraryCallCredentials.<clinit>(GoogleAuthLibraryCallCredentials.java:54) ~[grpc-auth-1.19.0.jar:1.19.0]
	at io.grpc.auth.MoreCallCredentials.from(MoreCallCredentials.java:35) ~[grpc-auth-1.19.0.jar:1.19.0]
	at com.google.api.gax.grpc.GrpcCallContext.withCredentials(GrpcCallContext.java:131) ~[gax-grpc-1.43.0.jar:1.43.0]
	at com.google.api.gax.grpc.GrpcCallContext.withCredentials(GrpcCallContext.java:64) ~[gax-grpc-1.43.0.jar:1.43.0]
	at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:165) ~[gax-1.43.0.jar:1.43.0]
	at com.google.cloud.pubsub.v1.stub.GrpcPublisherStub.create(GrpcPublisherStub.java:164) ~[google-cloud-pubsub-1.68.0.jar:1.68.0]
	at com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:152) ~[google-cloud-pubsub-1.68.0.jar:1.68.0]
	at com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:79) ~[google-cloud-pubsub-1.68.0.jar:1.68.0]
	at com.google.cloud.pubsub.v1.Publisher$Builder.build(Publisher.java:637) ~[google-cloud-pubsub-1.68.0.jar:1.68.0]
	at co.ipregistry.api.core.UsagePublisher.<init>(UsagePublisher.java:40) ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1295) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1197) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1247) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
	at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:67) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
	at my.app.Application.main(Application.java:15) ~[classes/:na]

Any additional information below

It seems the issue was introduced by version 1.68.0. Using version 1.67.0 is a possible workaround.

Activity

  1. laurentpellegrino commented on Apr 15, 2019

    @laurentpellegrino
    Author
  2. kolea2 commented on Apr 15, 2019

    @kolea2
    Contributor

    Hi @lpellegr, thanks for the report. Edited: Looks like my bom workaround is also giving me trouble, apologies.

    I believe that once a new version of gax is released, that should resolve the issue as that will include an auth library upgrade to 0.15.0. I'll investigate and reply back on the thread.

  3. added
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Apr 15, 2019
  4. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    and removed
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

dependenciespriority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions