graal icon indicating copy to clipboard operation
graal copied to clipboard

orai18n dependency causes native application startup failure - Missing character set id 560

Open syedyusufh opened this issue 1 year ago • 10 comments

Native Image Build is successful after adding the buildArgs as mentioned in https://github.com/oracle/graal/issues/8067, however the application start fails with the below error.

Missing character set id 560 not loaded at image build time at oracle.sql.CharacterSet.make(CharacterSet.java:114)

Sample application to reproduce the issue - https://github.com/syedyusufh/hello-sample.git

syedyusufh avatar Jan 27 '24 16:01 syedyusufh

What happens if you add -H:+AddAllCharsets to your list of build options? Does that fix your problem?

fniephaus avatar Jan 27 '24 19:01 fniephaus

Hi @fniephaus , thanks for the quick revert

Adding -H:+AddAllCharsets causes build failure with reference to CharacterSet classes

syedyusufh avatar Jan 28 '24 14:01 syedyusufh

After adding -H:+AddAllCharsets

Error: An object of type 'oracle.i18n.text.OraCharsetWithConverter' 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.i18n.text.OraCharsetWithConverter' are persisted in the image heap, add 

    '--initialize-at-build-time=oracle.i18n.text.OraCharsetWithConverter'

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.i18n.text.OraCharsetWithConverter' 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.i18n.text.OraCharsetWithConverter'

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.

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.i18n.text.OraCharsetWithConverter' 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.
Please address this problem to be prepared for future releases of GraalVM.

The following detailed trace displays from which field in the code the object was reached.
Trace: Object was reached by
  reading field java.util.HashMap$Node.value of constant 
    java.util.HashMap$Node@1315a658: x-oracle-th8macthai=X-ORACLE-TH8MACTHAI
  indexing into array java.util.HashMap$Node[]@60e0c6b4: [Ljava.util.HashMap$Node;@60e0c6b4
  reading field java.util.HashMap.table of constant 
    java.util.HashMap@4c1e5755: {csibm290=IBM290, ms-874=x-windows-874, x-oracle-i7siemens9780x=X-ORACLE-I7SIEME...
  scanning root java.util.HashMap@4c1e5755: {csibm290=IBM290, ms-874=x-windows-874, x-oracle-i7siemens9780x=X-ORACLE-I7SIEME... embedded in 
    com.oracle.svm.core.jdk.localization.substitutions.Target_java_nio_charset_Charset.lookup2(Target_java_nio_charset_Charset.java:82)
  parsing method com.oracle.svm.core.jdk.localization.substitutions.Target_java_nio_charset_Charset.lookup2(Target_java_nio_charset_Charset.java:76) reachable via the parsing context
    at java.nio.charset.Charset.lookup(Charset.java:476)
    at java.nio.charset.Charset.forName(Charset.java:540)
    at jdk.internal.util.xml.impl.XMLStreamWriterImpl.getCharset(XMLStreamWriterImpl.java:575)
    at jdk.internal.util.xml.impl.XMLStreamWriterImpl.writeStartDocument(XMLStreamWriterImpl.java:158)
    at jdk.internal.util.xml.impl.XMLStreamWriterImpl.writeStartDocument(XMLStreamWriterImpl.java:131)
    at jdk.internal.util.xml.impl.XMLStreamWriterImpl.writeStartDocument(XMLStreamWriterImpl.java:107)
    at jdk.internal.util.xml.PropertiesDefaultHandler.store(PropertiesDefaultHandler.java:103)
    at java.util.Properties.storeToXML(Properties.java:1132)
    at java.util.Properties.storeToXML(Properties.java:1083)
    at root method.(Unknown Source)

MoSehsah avatar Jan 29 '24 07:01 MoSehsah

Hi @syedyusufh, thank you for sharing with us your issue. We will be taking a look at it shortly.

kassifar avatar Jan 29 '24 10:01 kassifar

@fniephaus / @kassifar any other option to try, please. Thanks

syedyusufh avatar Feb 02 '24 02:02 syedyusufh

While we are still investigating this, we can unfortunately only provide you with workarounds. At this point, you could

  1. follow the instructions in the error message, adding --initialize-at-build-time=oracle.i18n.text.OraCharsetWithConverter to the list of your build option, re-build, repeat in case of more such errors
  2. Build with -H:-StrictImageHeap. Note that this option is only functional in GraalVM for JDK 21. It no longer works in JDK 22.

fniephaus avatar Feb 07 '24 16:02 fniephaus

Hi @fniephaus Resolved all the build errors reported for -H:+AddAllCharsets via --initialize-at-build-time, however the below error is again reported during application startup

Missing character set id 560 not loaded at image build time at oracle.sql.CharacterSet.make(CharacterSet.java:114)

syedyusufh avatar Feb 10 '24 14:02 syedyusufh

Ok, so I cannot reproduce the original issue with your reproducer repository and using Oracle GraalVM 21.0.2+13.1 on Linux x64. Also, I just realized your reproducer uses --strict-image-heap and marks two classes for build-time init. So this probably causes the build error that you are seeing.

fniephaus avatar Feb 15 '24 12:02 fniephaus

@fniephaus does the database you're using to reproduce has multilingual support enabled like both English & Arabic?

The below error is thrown only for multilingual enabled DB which requires orai18n dependency, otherwise it works perfectly fine Missing character set id 560 not loaded at image build time at oracle.sql.CharacterSet.make(CharacterSet.java:114)

syedyusufh avatar Feb 15 '24 15:02 syedyusufh

does the database you're using to reproduce has multilingual support enabled like both English & Arabic?

Nope, I wasn't aware that is a requirement. Is there an easy way to set this up, for example with test containers or so?

fniephaus avatar Feb 15 '24 16:02 fniephaus

I was just notified that the problem reported in https://github.com/oracle/graal/issues/8265#issuecomment-1914117149 will be fixed as part of the 23.4 release of the Oracle JDBC Driver jar. The “Missing character set id 560 not loaded at image build time” error should disappear when users switche to the latest version after 23.4 releases.

fniephaus avatar Mar 14 '24 10:03 fniephaus