tink icon indicating copy to clipboard operation
tink copied to clipboard

NoClassDefFoundError/ClassNotFoundException when using GcpKmsClient.register()

Open Rob3681 opened this issue 4 years ago • 8 comments

Describe the bug

I get the following exceptions when using GcpKmsClient.register():

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/json/jackson2/JacksonFactory
        at demo.App.main(App.java:22)
Caused by: java.lang.ClassNotFoundException: com.google.api.client.json.jackson2.JacksonFactory
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
        ... 1 more

My code looks something like this:

package demo;

import java.security.GeneralSecurityException;
import java.util.Optional;

import com.google.crypto.tink.integration.gcpkms.GcpKmsClient;

public class App {
    public static void main(String[] args) throws GeneralSecurityException {
        GcpKmsClient.register(Optional.of("gcp-kms://projects/xxxxx/locations/xxxxx/keyRings/xxxxx/cryptoKeys/xxxxx"), Optional.of("credentials.json"));
    }
}

My build.gradle file contains the following:

plugins {
    id 'application'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'com.google.crypto.tink:tink-gcpkms:1.6.1'
}

application {
    mainClass = 'demo.App'
}

Version information

  • Language: Java 16
  • Version: 1.6.1

Rob3681 avatar Sep 27 '21 15:09 Rob3681

Hmm, that's strange.

jackson-core is declared as a dependency in pom.xml.

Does it work if you add the following lines?

dependencies { implementation 'com.google.crypto.tink:tink-gcpkms:1.6.1' implementation 'com.fasterxml.jackson.core:jackson-core:2.12.1' }

thaidn avatar Nov 17 '21 18:11 thaidn

Same issue. You can seemingly quick-fix this by adding the following dependency

<dependency>
      <groupId>com.google.http-client</groupId>
      <artifactId>google-http-client-jackson2</artifactId>
      <version>1.40.1</version>
</dependency>

However, in there, the JacksonFactory is deprecated

StefanSchubert0001 avatar Nov 24 '21 13:11 StefanSchubert0001

same issue here ... seems like the dependency to com.google.http-client:google-http-client-jackson2 has been removed somewhere between com.google.cloud:google-cloud-pubsub:1.110.x and com.google.cloud:google-cloud-pubsub:1.113.x

we are using 2.0.4 of

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
    </dependency>

and

      <dependency>
        <groupId>com.google.crypto.tink</groupId>
        <artifactId>tink</artifactId>
        <version>1.6.1</version>
      </dependency>
      <dependency>
        <groupId>com.google.crypto.tink</groupId>
        <artifactId>tink-gcpkms</artifactId>
        <version>1.6.1</version>
      </dependency>

marcelsauer4711 avatar Nov 24 '21 13:11 marcelsauer4711

Same issue here

tobiasendres avatar Nov 25 '21 07:11 tobiasendres

Someone reported in https://github.com/google/tink/issues/557 that upgrading to the latest version resolves the problem for them.

Have you tried that?

thaidn avatar Nov 30 '21 16:11 thaidn

I'm facing the same issue.

The Tink GCP KMS extension references the class com.google.api.client.json.jackson2.JacksonFactory in its com.google.crypto.tink.integration.gcpkms.GcpKmsClient class. However, there is no dependency to com.google.http-client:google-http-client-jackson2 declared anywhere in its pom.xml file.

It seems people are just lucky by having the above mentioned dependency in their classpath when working with GCP anyway, and that's why it works for them.

Furthermore, adding jackson-core as a dependency cannot solve the issue, because the missing class is not from Jackson but from the Google HTTP Client Library for Java. It seems that apart from the JacksonFactory usage, the Jackson library is completely unused, which means the dependencies to jackson-core, jackson-databind and jackson-databind-cbor can be removed altogether.

Moreover, the JacksonFactory is deprecated, it should be replaced with GsonFactory.

janhicken avatar Jan 10 '22 16:01 janhicken

Thanks. I'm taking a look and see that this should be fixed in 1.7.

thaidn avatar Jan 10 '22 16:01 thaidn

I think this issue has been fixed with 2069a8080c40b1e6a821d3e44e0cb3f3022bbedc.

However, there seems to be no release to include that fix yet.

janhicken avatar Jun 21 '22 08:06 janhicken

Tink 1.7 was released in August 2022, and I think this should be fixed in 1.7. So I'm going to close this now. Please re-open if you think it is still a problem in 1.7.

juergw avatar Jan 30 '23 12:01 juergw