Graal: issue with okhttp with graalvm-ce-19.0.0

Created on 15 May 2019  路  8Comments  路  Source: oracle/graal

With graalvm-ce-19.0.0 I get

...
Caused by: java.nio.charset.UnsupportedCharsetException: UTF-32BE
    at java.nio.charset.Charset.forName(Charset.java:531)
    at okhttp3.internal.Util.<clinit>(Util.java:75)
    at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:347)
    at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:267)

Which I did not have with the RC candidates...
Is it a regression or a feature? Any workaround?
https://github.com/square/okhttp/blob/5cfa0bb3e6d1cdba89761806ff6999f59a15c0eb/okhttp/src/main/java/okhttp3/internal/Util.java#L84
did not change in my tests between RCs and 19.0.0.

native-image

Most helpful comment

Try the -H:+AddAllCharsets command line option when running the native image generator.

from the help text:

-H:卤AddAllCharsets Make all hosted charsets available at run time. Default: - (disabled).

All 8 comments

Correction: I changed the okhttp version so this is not related to the 19.0.0 release.
Anyway, the bug is valid with this version of okhttp3

Solution: add this in your reflect.json configuration

  {
  "name" : "sun.nio.cs.ext.ExtendedCharsets",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredClasses" : true,
    "allPublicClasses" : true
  }

As this class in initialized via reflection in the OpenJDK Charset class.

Sorry, spoke too soon... My json file does not fix this...

Try the -H:+AddAllCharsets command line option when running the native image generator.

from the help text:

-H:卤AddAllCharsets Make all hosted charsets available at run time. Default: - (disabled).

We changed class initialization to delay class to runtime by default. This exposes extra JNI functions that were not there before. You can find out more here.

Great, thanks for the info in the flag which works. Feel free to close the bug, I am sure it will help others even if closed.

What is the best way to add just those 2 charsets (without using -H:卤AddAllCharsets)?

I have seen implementation in LocalizationFeature, but even with static initialization in my cade, when a class is put into build_time_classes*.txt, it still fails with java.nio.charset.UnsupportedCharsetException: UTF-32BE.

@szpak Did you ever figure that out?

Was this page helpful?
0 / 5 - 0 ratings