spring-projects / spring-data-cassandra

Provides support to increase developer productivity in Java when using Apache Cassandra. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-cassandra/
Apache License 2.0
376 stars 309 forks source link

`com.datastax.oss.driver.internal.core.util.Dependency` was unintentionally initialized at build time #1340

Closed acemoo closed 1 year ago

acemoo commented 1 year ago

When trying to natively compile a project that has both spring-boot-starter-data-cassandra and spring-cloud-starter-stream-kafka using mvn clean -Pnative native:compile I'm getting the following error:

Error: Classes that should be initialized at run time got initialized during image building:
 com.datastax.oss.driver.internal.core.util.Dependency was unintentionally initialized at build time.

Here's a minimal project that shows the problem: https://github.com/acemoo/spring-native-cloud-kafka-data-cassandra

I found a similar issue with Micronaut https://github.com/micronaut-projects/micronaut-cassandra/issues/263 With a solution https://github.com/micronaut-projects/micronaut-cassandra/pull/264/files Unfortunately, I couldn't find any --initialize-at-build-time in either Spring Boot or Spring Data Cassandra.

mp911de commented 1 year ago

Please report the issue against the Cassandra driver directly. All those linked tickets seem like workarounds.

Can you attach a trace from where the initialization of Dependency is triggered?

mp911de commented 1 year ago

Initialization stack trace shows that com.datastax.oss.driver.internal.core.util.Dependency is initialized by a substitution shipped in the Cassandra driver:

Error: Classes that should be initialized at run time got initialized during image building:
 com.datastax.oss.driver.internal.core.util.Dependency was unintentionally initialized at build time. com.datastax.oss.driver.internal.core.util.Dependency caused initialization of this class with the following trace: 
    at com.datastax.oss.driver.internal.core.util.Dependency.<clinit>(Dependency.java:33)
    at com.datastax.dse.driver.internal.core.type.codec.DseTypeCodecsRegistrarSubstitutions$EsriMissing.getAsBoolean(DseTypeCodecsRegistrarSubstitutions.java:42)
    at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.findTargetClass(AnnotationSubstitutionProcessor.java:1014)
    at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:364)
    at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:342)
    at com.oracle.svm.hosted.NativeImageGenerator.createAnnotationSubstitutionProcessor(NativeImageGenerator.java:966)
    at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:868)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:575)
    at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
acemoo commented 1 year ago

A bit of a slow response from my side, Just got time to dive into this again. Seems it will be solved in 4.15.1 https://datastax-oss.atlassian.net/browse/JAVA-3045

patpatpat123 commented 1 year ago

Hello @acemoo , thank you for finding this issue.

Do you know if there is a way to import 4.15.1 to the current SpringBoot 3.0.2 or 3.0.3 snapshot please?

mp911de commented 1 year ago

4.15.1 isn't released yet. In any case, you can override the Spring Boot property cassandra-driver.version with <cassandra-driver.version>4.15.1</cassandra-driver.version>.

patpatpat123 commented 1 year ago

Many thanks @mp911de, I will wait for the release of 4.15.1 and apply what you said