Description
Introducing com.oracle.database.jdbc:ojdbc11:21.9.0.0 into the application and then packaging it as Native will result in a serialization error.
The error is consistent with quarkusio oracle driver and serialization conflict.
Cause of the error
The reason for the error is that there is a file oracle.nativeimage.Target_java_io_ObjectStreamClass in the oracle driver, which replaces the code of java.io.ObjectStreamClass during graalVM compilation.
Solution
In quarkus, there is a RemovedResourceBuildItem that can delete a class file of a certain Jar package before compilation. This is quarkus’s solution.
I haven’t found anything similar in SpringBoot yet, so I currently repackaged the oracle driver and uploaded it to my own maven repository.
Is there a more elegant solution in SpringBoot?
Exception prompt
Logging system failed to initialize using configuration from 'null'
java.lang.RuntimeException: Failed to load model from 'META-INF/spring/logback-model'
at org.springframework.boot.logging.logback.SpringBootJoranConfigurator$ModelReader.read(SpringBootJoranConfigurator.java:318)
at org.springframework.boot.logging.logback.SpringBootJoranConfigurator.configureUsingAotGeneratedArtifacts(SpringBootJoranConfigurator.java:114)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initializeFromAotGeneratedArtifactsIfPossible(LogbackLoggingSystem.java:210)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:187)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
at java.base@17.0.5/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:352)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
at com.psd.act.service.ActApplicationKt.main(ActApplication.kt:32)
Caused by: java.lang.IllegalStateException: Object serialization is currently not supported
at java.base@17.0.5/java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:60)
at java.base@17.0.5/java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:2017)
at java.base@17.0.5/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1898)
at java.base@17.0.5/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2224)
at java.base@17.0.5/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1733)
at java.base@17.0.5/java.io.ObjectInputStream.readObject(ObjectInputStream.java:509)
at java.base@17.0.5/java.io.ObjectInputStream.readObject(ObjectInputStream.java:467)
at org.springframework.boot.logging.logback.SpringBootJoranConfigurator$ModelReader.read(SpringBootJoranConfigurator.java:312)
... 23 more
Environment
- Spring Boot version number: 3.0.2
- GraalVM version number: graalvm64-ce-17.0.5-22.3.0
- OracleDriver version number: com.oracle.database.jdbc:ojdbc11:21.9.0.0
- Operating system information: MacOS
Steps to reproduce
- 1.Create a new Spring Boot project and add Oracle database dependencies;
- 2.Configure Oracle database connection and use Oracle database Driver;
- 3.Build the application into a Native image;
- 4.Start the Native image and the above error message appears.
Comment From: damianopittori
Hello,
I was about to open the same bug today 😄
My solution, other then 'repackaged the oracle driver', was to downgrade the ojdbc version to 21.1.0.0, since the class performing that substitution was introduced in v21.3.0.0.
Here's a repo to replicate the issue (don't need to use the ojdbc, just being in the classpath toghether with spring-boot-starter-logging and using a logback.xml or logback-spring.xml) : spring-native-ojdbc
Environment
- Spring Boot version number: 3.0.5
- GraalVM version number: GraalVM CE 22.3.1
- OracleDriver version number: com.oracle.database.jdbc:ojdbc11:21.7.0.0
- Operating system information: Oracle Linux Server 8.7
Comment From: snicoll
@damianopittori thanks for the sample.
@a483210 this is an issue in the Oracle driver that disables core JDK features via a substitution. There's nothing we can do about it. I'll do my best to share the issue but if you have a support contract, please report it as well.
Comment From: damianopittori
The issue has been fixed in the latest version of the Oracle driver com.oracle.database.jdbc:ojdbc11:23.2.0.0 released on April 07, 2023.
Comment From: snicoll
@damianopittori thanks. I also got in touch with the team at Oracle and they will backport the fix to 21.9 if I understood correctly.
Comment From: maradanasai
@snicoll Even with 21.9 version, able to reproduce this issue.
I'm using spring boot 3.2.2 and native-image-community:21-ol8 jdk version
Comment From: wilkinsona
@maradanasai Oracle may not yet have back ported the fix to 21.9, we don't know. You'll have to ask Oracle for up-to-date information on the status of any back port.
Comment From: maradanasai
Got it @wilkinsona Are there any work arounds to get it fixed temporarily?
Comment From: wilkinsona
@a483210 describes their approach above. You may want to try doing the same. Beyond that, you may want to ask the GraalVM community if it's possible to ignore a substitution or to reverse a substitution's effects so that serialization isn't disabled.