Graal: Native image fails at runtime with standard charsets used in MySQL

Created on 6 Oct 2020  路  6Comments  路  Source: oracle/graal

"WINDOWS-1252" is a fallback charset for the MySQL JDBC client. It works in a regular JVM, but fails in a native image. Here's a short repro:

$ cat Foo.java
public class Foo {
        public static void main(String[] args) {
                System.out.println(java.nio.charset.Charset.forName("WINDOWS-1252"));
        }
}
$ java Foo
windows-1252
$ native-image Foo
[foo:382571]    classlist:   1,056.43 ms,  1.17 GB
[foo:382571]        (cap):     748.43 ms,  1.17 GB
[foo:382571]        setup:   1,976.60 ms,  1.67 GB
[foo:382571]     (clinit):      67.83 ms,  1.72 GB
[foo:382571]   (typeflow):   2,912.83 ms,  1.72 GB
[foo:382571]    (objects):   2,656.84 ms,  1.72 GB
[foo:382571]   (features):     142.88 ms,  1.72 GB
[foo:382571]     analysis:   5,912.91 ms,  1.72 GB
[foo:382571]     universe:     194.29 ms,  1.72 GB
[foo:382571]      (parse):     516.02 ms,  1.72 GB
[foo:382571]     (inline):     732.86 ms,  1.77 GB
[foo:382571]    (compile):   3,312.28 ms,  1.88 GB
[foo:382571]      compile:   4,797.81 ms,  1.88 GB
[foo:382571]        image:     426.83 ms,  1.88 GB
[foo:382571]        write:     117.93 ms,  1.88 GB
[foo:382571]      [total]:  14,716.07 ms,  1.88 GB
$ ./foo
Exception in thread "main" java.nio.charset.UnsupportedCharsetException: WINDOWS-1252
        at java.nio.charset.Charset.forName(Charset.java:531)
        at Foo.main(Foo.java:3)
bug native-image spring

All 6 comments

Hello @dsyer,
Can you please share the version of GraalVM you used?

$ native-image --version
GraalVM Version 20.3.0-dev (Java Version null)

It's the same with 20.2 I think.

Hey @dsyer! Looking at com/oracle/svm/core/jdk/LocalizationFeature.java:164, that charset is not added to the native-image by default. You can try building the native-image with -H:+AddAllCharsets, this should include WINDOWS-1252 but it will also include a bunch of other charsets too, making the image bigger.

@dsyer I was able to build/run the Foo example without the -H:+AddAllCharsets suggested by @gradinac.

image

Please try -H:+AddAllCharsets and let us know if the problem persists

Thanks, that works for my MySQL sample as well (but adds 7MB to the image size!). It's better to tell MySQL to use UTF-8 explicitly.

Thanks @dsyer and @gradinac!

Was this page helpful?
0 / 5 - 0 ratings