Graal: URL parsing without --enable-https is broken

Created on 8 Oct 2018  路  1Comment  路  Source: oracle/graal

Imagine the following example:

public static void main(String[] args) throws MalformedURLException {
  URL url = new URL("https://www.google.com");
  System.out.println(url);
}

If this native image is built without enabling https support, the runtime process fails with:

./my-image
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 java.lang.Throwable.<init>(Throwable.java:265)
        at java.lang.Error.<init>(Error.java:70)
        at com.oracle.svm.core.jdk.UnsupportedFeatureError.<init>(UnsupportedFeatureError.java:31)
        at com.oracle.svm.core.jdk.Target_com_oracle_svm_core_util_VMError.unsupportedFeature(VMErrorSubstitutions.java:109)
        at com.oracle.svm.core.jdk.JavaNetSubstitutions.unsupported(JavaNetSubstitutions.java:169)
        at com.oracle.svm.core.jdk.JavaNetSubstitutions.getURLStreamHandler(JavaNetSubstitutions.java:156)
        at com.oracle.svm.core.jdk.Target_java_net_URL.getURLStreamHandler(JavaNetSubstitutions.java:59)
        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.example.myapp.Main.main(MainVerticle.java:26)
        at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:163)

I'd expect that this kind of exception would only occur if I'd try to request a URLConnection not just a URL instance.

feature native-image

Most helpful comment

j.n.URL does some basic validation during parsing, including checking if a handler for the protocol exists.
The doc guarantees that the https protocol handler is available.
A workaround could be (without --enable-https) provide a dummy https handler that fails when opening a connection, allowing URL protocol validation to succeed.
The current approach is totally reasonable along SVM mantras.

>All comments

j.n.URL does some basic validation during parsing, including checking if a handler for the protocol exists.
The doc guarantees that the https protocol handler is available.
A workaround could be (without --enable-https) provide a dummy https handler that fails when opening a connection, allowing URL protocol validation to succeed.
The current approach is totally reasonable along SVM mantras.

Was this page helpful?
0 / 5 - 0 ratings