Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with okhttp with graalvm-ce-19.0.0 #1294

Closed
ludoch opened this issue May 15, 2019 · 11 comments
Closed

issue with okhttp with graalvm-ce-19.0.0 #1294

ludoch opened this issue May 15, 2019 · 11 comments
Assignees

Comments

@ludoch
Copy link

ludoch commented May 15, 2019

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.

@ludoch
Copy link
Author

ludoch commented May 15, 2019

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

@ludoch
Copy link
Author

ludoch commented May 15, 2019

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.

@ludoch
Copy link
Author

ludoch commented May 16, 2019

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

@causalnet
Copy link

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).

@vjovanov
Copy link
Member

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.

@vjovanov vjovanov assigned vjovanov and unassigned cstancu May 16, 2019
@ludoch
Copy link
Author

ludoch commented May 17, 2019

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.

@szpak
Copy link

szpak commented Jul 9, 2019

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.

@apple-corps
Copy link

@szpak Did you ever figure that out?

@visruth
Copy link

visruth commented Dec 3, 2022

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).

Great! This solves the issue. It worked for me. Thank you @causalnet.

@wirthi
Copy link
Member

wirthi commented Feb 1, 2024

Problem has long been resolved, closing.

@wirthi wirthi closed this as completed Feb 1, 2024
@gstaykov
Copy link

gstaykov commented Jun 4, 2024

for those using maven plugin you can add -H:+AddAllCharsets like this:

            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <imageName>${project.name}</imageName>
                    <fallback>false</fallback>
                    <verbose>true</verbose>
                    <quickBuild>true</quickBuild>
                    <buildArgs>
                        <arg>-H:+AddAllCharsets</arg>
                    </buildArgs>
                    <metadataRepository>
                        <enabled>true</enabled>
                    </metadataRepository>
                </configuration>
            </plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants