Native image build fails if orai18n.jar is included as a dependency
Error: An object of type 'oracle.sql.converter.I18CharacterConvertersWrapper' was found in the image heap.
Below is a minimal sample to reproduce the problem,
https://github.com/syedyusufh/hello-sample.git
Comment From: snicoll
Thanks for the report but this is failing differently for me using 23.0.1
:
[WARNING] Properties file at 'jar:file:///Users/snicoll/.m2/repository/com/oracle/database/jdbc/ojdbc11/23.3.0.23.09/ojdbc11-23.3.0.23.09.jar!/META-INF/native-image/native-image.properties' does not match the recommended 'META-INF/native-image/com.oracle.database.jdbc/ojdbc11/native-image.properties' layout.
And:
Warning: Using a deprecated option --allow-incomplete-classpath from 'META-INF/native-image/native-image.properties' in 'file:///Users/snicoll/.m2/repository/com/oracle/database/jdbc/ojdbc11/23.3.0.23.09/ojdbc11-23.3.0.23.09.jar'. Allowing an incomplete classpath is now the default. Use --link-at-build-time to report linking errors at image build time for a class or package.
Error: Unrecognized option: --strict-image-heap
Neither of those are related to Spring so this should be reported to Oracle. How can I reproduce the issue you've described?
Comment From: syedyusufh
Thanks @snicoll for the quick revert. I am using GraalVM CE for Jdk 21.0.1 (latest)
Have used --strict-image-heap
based on the recommended fix for https://github.com/spring-projects/spring-framework/issues/31806
Can you please run as below?
mvn -Pnative package
--> Spring AOTmvn -Pnative native:compile
--> Native Build on Spring AOT generated
P.S: We don't use Paketo due to security vulnerabilities on Paketo images
Comment From: snicoll
Thanks for the follow-up, I wasn't aware of the change in 21-based builds. That being said, I don't understand why this is reported here.
Here's an excerpt of the message:
Error: An object of type 'oracle.sql.converter.I18CharacterConvertersWrapper' was found in the image heap. This type, however, is marked for initialization at image run time for the following reason: classes are initialized at run time by default.
This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time.
You now have two options to resolve this:
1) If it is intended that objects of type 'oracle.sql.converter.I18CharacterConvertersWrapper' are persisted in the image heap, add
'--initialize-at-build-time=oracle.sql.converter.I18CharacterConvertersWrapper'
to the native-image arguments. Note that initializing new types can store additional objects to the heap. It is advised to check the static fields of 'oracle.sql.converter.I18CharacterConvertersWrapper' to see if they are safe for build-time initialization, and that they do not contain any sensitive data that should not become part of the image.
2) If these objects should not be stored in the image heap, you can use
'--trace-object-instantiation=oracle.sql.converter.I18CharacterConvertersWrapper'
to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with
'--initialize-at-run-time=<culprit>'
to prevent the instantiation of the object.
You can then add the property and see that Spring isn't involved at all:
The culprit object has been instantiated with the following trace:
at oracle.sql.converter.I18CharacterConvertersWrapper.<init>(I18CharacterConvertersWrapper.java:61)
at oracle.sql.converter.CharacterConverterFactoryOGS.make(CharacterConverterFactoryOGS.java:46)
at oracle.sql.CharacterSetWithConverter.getInstance(CharacterSetWithConverter.java:99)
at oracle.sql.CharacterSetFactoryThin.make(CharacterSetFactoryThin.java:130)
at oracle.sql.CharacterSet$$Lambda/0x0000007003242ac0.apply(Unknown Source)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1740)
at oracle.sql.CharacterSet.make(CharacterSet.java:519)
at java.lang.invoke.DirectMethodHandle$Holder.invokeStatic(DirectMethodHandle$Holder)
at java.lang.invoke.LambdaForm$MH/0x0000007002c0d000.invoke(LambdaForm$MH)
at java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder)
at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(DirectMethodHandleAccessor.java:154)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.lang.reflect.Method.invoke(Method.java:580)
at oracle.nativeimage.CharacterSetFeature.duringAnalysis(CharacterSetFeature.java:86)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$10(NativeImageGenerator.java:786)
at com.oracle.svm.hosted.NativeImageGenerator$$Lambda/0x0000007003247848.accept(Unknown Source)
at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:90)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:786)
at com.oracle.svm.hosted.NativeImageGenerator$$Lambda/0x0000007002ab0460.apply(Unknown Source)
at com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:181)
at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:783)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:592)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:550)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:543)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:725)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.start(NativeImageGeneratorRunner.java:142)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:97)
Then, this is relevant:
If you are seeing this message after enabling '--strict-image-heap', this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time.
To fix this, include '--initialize-at-build-time=oracle.sql.converter.I18CharacterConvertersWrapper' in your configuration. If the classes do not originate from your code, it is advised to update all library or framework dependencies to the latest version before addressing this error.
So, please report that to Oracle.