Repository navigation
Closed
Labels
Description
I have a reproducible example here:
https://github.com/bootstraponline/native-image-GenericJson
Tested on graalvm-ce-1.0.0-rc11 with Java 1.8.0_192 on macOS 10.14.2
Run ./native_build.sh
Run ./gtest
Observe
./gtest
Exception in thread "main" com.oracle.svm.core.jdk.UnsupportedFeatureError: Accessing an URL protocol that was not enabled. The URL protocol https is supported but not enabled by default. It must be enabled by adding the --enable-url-protocols=https option to the native-image command.
at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:109)
at com.oracle.svm.core.jdk.JavaNetSubstitutions.unsupported(JavaNetSubstitutions.java:164)
at com.oracle.svm.core.jdk.JavaNetSubstitutions.getURLStreamHandler(JavaNetSubstitutions.java:151)
at java.net.URL.getURLStreamHandler(URL.java:60)
at java.net.URL.<init>(URL.java:599)
at java.net.URL.<init>(URL.java:490)
at java.net.URL.<init>(URL.java:439)
at com.google.api.client.http.GenericUrl.parseURL(GenericUrl.java:637)
at com.google.api.client.http.GenericUrl.<init>(GenericUrl.java:115)
at com.google.api.client.auth.oauth2.Credential$Builder.setTokenServerEncodedUrl(Credential.java:746)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential$Builder.setTokenServerEncodedUrl(GoogleCredential.java:832)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential$Builder.<init>(GoogleCredential.java:563)
at com.google.api.client.googleapis.testing.auth.oauth2.MockGoogleCredential$Builder.<init>(MockGoogleCredential.java:58)
at gtest.Main$Companion$defaultCredential$2.invoke(Main.kt:31)
at gtest.Main$Companion$defaultCredential$2.invoke(Main.kt:12)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at gtest.Main$Companion.getDefaultCredential(Main.kt)
at gtest.Main$Companion$toolResults$2.invoke(Main.kt:22)
at gtest.Main$Companion$toolResults$2.invoke(Main.kt:12)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at gtest.Main$Companion.getToolResults(Main.kt)
at gtest.Main$Companion.main(Main.kt:48)
at gtest.Main.main(Main.kt)
In addition I also see:
Caused by: java.lang.IllegalArgumentException: unable to create new instance of class com.google.api.client.json.GenericJson because it has no accessible default constructor
at com.google.api.client.util.Types.handleExceptionForNewInstance(Types.java:165)
at com.google.api.client.util.Types.newInstance(Types.java:120)
at com.google.api.client.util.Data.newMapInstance(Data.java:526)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:763)
... 37 more
Caused by: java.lang.InstantiationException: Type `com.google.api.client.json.GenericJson` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
at java.lang.Class.newInstance(DynamicHub.java:652)
at com.google.api.client.util.Types.newInstance(Types.java:116)
... 39 more
which is not solved by:
[
{
"name" : "com.google.api.client.json.GenericJson",
"methods": [
{ "name": "<init>", "parameterTypes": [] }
],
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true
},Also...
Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: sun.security.provider.NativePRNG
Trace: object java.security.SecureRandom
object sun.security.ssl.SSLContextImpl$TLSContext
object sun.security.ssl.SSLSocketFactoryImpl
object com.google.api.client.http.javanet.NetHttpTransport
field gtest.gcloud.Config.HTTP_TRANSPORT
Error: Image building with exit status 1
Graal native images are unable to make basic HTTP requests to Google services using the Java client libraries.
Reacted by Thomas
Activity
sniperliu commentedon Feb 28, 2019
Same here, use goolge api
ludoch commentedon Mar 13, 2019
For Cloud Datastore (link above), the error is like:
nhoughto commentedon Jul 2, 2019
Hmm feels like this should work with latest graal builds?
The above error is likely a reflection config problem?
jramirez-isc commentedon Oct 1, 2019
@bootstraponline you can try with GraalVM version 19.2.0 or later. Also, use the native-image-agent to automatically detect reflectively accessed elements.
I did some local testing using your code, and I had to modify some of the options:
Note:
-H:ConfigurationFileDirectories=config-diris referencing the folder generated by the native-image-agent.One thing I noticed is when I run the .jar itself with
java -jar build/libs/gtest-SNAPSHOT.jarthe output is this:And when I run the generated native-image with
./gtestI get the same output. Despite the exception, the native-image is supposedly okay.bootstraponline commentedon Oct 1, 2019
Thanks! I think that's the correct result. On previous versions of Graal, the request itself wasn't sent. The simple example is using a mock server with a mock credential so it's not intended to connect.
I'll close this issue as solved.
Merge pull request oracle#926