Quarkus: HttpURLConnection Caused String.getBytes() NoSuchMethodError, Quarkus 1.3.0.Final and GraalVM 20.0.0 on Windows

Created on 23 Mar 2020  Â·  12Comments  Â·  Source: quarkusio/quarkus

Describe the bug
HttpURLConnection Caused String.getBytes() NoSuchMethodError, Quarkus 1.3.0.Final and GraalVM 20.0.0 on Windows

Expected behavior
No error.

Actual behavior
Caused by: java.lang.NoSuchMethodError: java.lang.String.getBytes()[B
at com.oracle.svm.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1095)
at com.oracle.svm.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1080)
at com.oracle.svm.jni.functions.JNIFunctions.GetMethodID(JNIFunctions.java:384)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java)
at java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1515)
at java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
at java.net.InetAddress.getAllByName0(InetAddress.java:1505)
at java.net.InetAddress.getAllByName(InetAddress.java:1364)
at java.net.InetAddress.getAllByName(InetAddress.java:1298)
at java.net.InetAddress.getByName(InetAddress.java:1248)
at java.net.InetSocketAddress.(InetSocketAddress.java:220)
at sun.net.NetworkClient.doConnect(NetworkClient.java:182)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:265)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1187)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:334)

To Reproduce
Steps to reproduce the behavior:

  1. download quarkus-example.zip
  2. gradle clean
  3. gradle --configure-on-demand -x check buildNative
  4. Visit url http://localhost:8080/demo

Configuration

None

Screenshots
None

Additional context
@gwenneg https://github.com/quarkusio/quarkus/issues/7269

enwindows kinbug triaginvalid

Most helpful comment

@geoand @gwenneg

I got to the root of the problem.

My Windows OS Locale is Chinese,

Though Graal native-image build is succeeded,

But runtime execute hi.exe is NoSuchMethodError.

This error is Graal native-image‘s problem, I switch OS Locale to English it works!


import java.net.InetAddress;
import java.net.UnknownHostException;
public class Hi {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
    InetAddress inetAddress;
    try {
        inetAddress = InetAddress.getLocalHost();
        System.out.println("IP of my system is: " + inetAddress.getHostAddress());
        System.out.println("Name of my system is: " + inetAddress.getHostName());
    } catch (UnknownHostException ex) {
        System.err.println(ex);
    }
  }
}

C:\Users\xiaodong\Desktop\demo>java Hi
Picked up JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF-8"
Hello, World!
IP of my system is: 192.168.1.239
Name of my system is: DESKTOP-1234567

C:\Users\xiaodong\Desktop\demo> native-image Hi
Picked up JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF-8"
[hi:13176] classlist: 1,109.85 ms, 1.00 GB
[hi:13176] (cap): 2,128.20 ms, 1.23 GB
[hi:13176] setup: 3,831.19 ms, 1.23 GB
[hi:13176] (typeflow): 6,434.27 ms, 1.67 GB
[hi:13176] (objects): 5,804.55 ms, 1.67 GB
[hi:13176] (features): 290.73 ms, 1.67 GB
[hi:13176] analysis: 12,814.14 ms, 1.67 GB
[hi:13176] (clinit): 165.90 ms, 1.67 GB
[hi:13176] universe: 460.63 ms, 1.67 GB
[hi:13176] (parse): 1,036.31 ms, 2.01 GB
[hi:13176] (inline): 978.26 ms, 2.01 GB
[hi:13176] (compile): 6,578.22 ms, 2.01 GB
[hi:13176] compile: 8,965.07 ms, 2.01 GB
[hi:13176] image: 898.84 ms, 2.01 GB
[hi:13176] write: 272.64 ms, 2.01 GB
C:\Users\xiaodong\Desktop\demo> hi.exe
Hello, World!
Exception in thread "main" java.lang.NoSuchMethodError: java.lang.String.([B)V
at com.oracle.svm.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1095)
at com.oracle.svm.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1080)
at com.oracle.svm.jni.functions.JNIFunctions.GetMethodID(JNIFunctions.java:384)
at java.net.Inet6AddressImpl.getLocalHostName(Inet6AddressImpl.java)
at java.net.InetAddress.getLocalHost(InetAddress.java:1623)
at Hi.main(Hi.java:8)

All 12 comments

Hello,

Your reproducer is using version 1.3.0.CR1. Can you please try using 1.3.0.Final?
I also tried building a native binary with your reproducer and it didn't work at all.

@geoand
Yes,1.3.0.CR1 and 1.3.0.Final didn't work at all

@iwangxiaodong I mean I could not reproduce your error. I was just getting an error during the native image build.

@iwangxiaodong can you update the reproducer with the latest code that you used to build the native image?

@geoand

I get it. I modified my quarkus-example.zip.
You can download it again.

GraalVM 20.0.0 in Windows 10 x64:

  Install Visual Studio Community 2017 (C++ components)

  SET GRAALVM_HOME="G:...\graalvm-ce-java11-20.0.0"
  SET PATH="%PATH%;%GRAALVM_HOME%\bin"
  gu available
  gu install native-image

  cd C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2017\Visual Studio Tools\VC
  Click "x64 Native Tools Command Prompt for VS 2017"
  cd D:\...\quarkus-example
  set JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8"
  G:\gradle-6.1.1-bin\gradle-6.1.1\bin\gradle clean
  G:\gradle-6.1.1-bin\gradle-6.1.1\bin\gradle --configure-on-demand -x check buildNative

Build time is Successful, runtime is Internal Server Error

Visit url http://localhost:8080/demo Caused by: java.lang.NoSuchMethodError: java.lang.String.getBytes()[B

Thank you!

I still can't build the native image with your reproducer (I am using Linux). So maybe someone with a Windows machine can give it a shot

Yes, Only In Windows Caused.

FWIW, native image is just a preview on Windows

OK. Hope support as soon as possible.

To be clear, the limitation I mentioned above is a GraalVM limitation, not a Quarkus limitation

Hi @iwangxiaodong!

I tried reproducing your issue, but it works perfectly fine on my test environment, which is composed of:

  • Windows 10 x64
  • graalvm-ce-java11-20.0.0
  • Gradle 6.2.2 (the current recommended Gradle version with Quarkus)
  • the second reproducer you uploaded above

When I run the native executable and visit http://localhost:8080/demo, here's what I'm seeing in the server log:

__  ____  __  _____   ___  __ ____  ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2020-03-23 20:49:01,214 INFO  [io.quarkus] (main) quarkus-example unspecified (powered by Quarkus 1.3.0.Final) started in 0.022s. Listening on: http://0.0.0.0:8080
2020-03-23 20:49:01,214 INFO  [io.quarkus] (main) Profile prod activated.
2020-03-23 20:49:01,215 INFO  [io.quarkus] (main) Installed features: [cdi, resteasy]
<!doctype html><html><head>    <title>Example Domain</title>    <meta charset="utf-8" />    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />    <meta name="viewport" content="width=device-width, initial-scale=1" />    <style type="text/css">    body {        background-color: #f0f0f2;        margin: 0;        padding: 0;        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;            }    div {        width: 600px;        margin: 5em auto;        padding: 2em;        background-color: #fdfdff;        border-radius: 0.5em;        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);    }    a:link, a:visited {        color: #38488f;        text-decoration: none;    }    @media (max-width: 700px) {        div {            margin: 0 auto;            width: auto;        }    }    </style>    </head><body><div>    <h1>Example Domain</h1>    <p>This domain is for use in illustrative examples in documents. You may use this    domain in literature without prior coordination or asking for permission.</p>    <p><a href="https://www.iana.org/domains/example">More information...</a></p></div></body></html>

There must be a difference between my environment and yours that explains the NoSuchMethodError. Which Gradle version are you using?

@geoand @gwenneg

I got to the root of the problem.

My Windows OS Locale is Chinese,

Though Graal native-image build is succeeded,

But runtime execute hi.exe is NoSuchMethodError.

This error is Graal native-image‘s problem, I switch OS Locale to English it works!


import java.net.InetAddress;
import java.net.UnknownHostException;
public class Hi {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
    InetAddress inetAddress;
    try {
        inetAddress = InetAddress.getLocalHost();
        System.out.println("IP of my system is: " + inetAddress.getHostAddress());
        System.out.println("Name of my system is: " + inetAddress.getHostName());
    } catch (UnknownHostException ex) {
        System.err.println(ex);
    }
  }
}

C:\Users\xiaodong\Desktop\demo>java Hi
Picked up JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF-8"
Hello, World!
IP of my system is: 192.168.1.239
Name of my system is: DESKTOP-1234567

C:\Users\xiaodong\Desktop\demo> native-image Hi
Picked up JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF-8"
[hi:13176] classlist: 1,109.85 ms, 1.00 GB
[hi:13176] (cap): 2,128.20 ms, 1.23 GB
[hi:13176] setup: 3,831.19 ms, 1.23 GB
[hi:13176] (typeflow): 6,434.27 ms, 1.67 GB
[hi:13176] (objects): 5,804.55 ms, 1.67 GB
[hi:13176] (features): 290.73 ms, 1.67 GB
[hi:13176] analysis: 12,814.14 ms, 1.67 GB
[hi:13176] (clinit): 165.90 ms, 1.67 GB
[hi:13176] universe: 460.63 ms, 1.67 GB
[hi:13176] (parse): 1,036.31 ms, 2.01 GB
[hi:13176] (inline): 978.26 ms, 2.01 GB
[hi:13176] (compile): 6,578.22 ms, 2.01 GB
[hi:13176] compile: 8,965.07 ms, 2.01 GB
[hi:13176] image: 898.84 ms, 2.01 GB
[hi:13176] write: 272.64 ms, 2.01 GB
C:\Users\xiaodong\Desktop\demo> hi.exe
Hello, World!
Exception in thread "main" java.lang.NoSuchMethodError: java.lang.String.([B)V
at com.oracle.svm.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1095)
at com.oracle.svm.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1080)
at com.oracle.svm.jni.functions.JNIFunctions.GetMethodID(JNIFunctions.java:384)
at java.net.Inet6AddressImpl.getLocalHostName(Inet6AddressImpl.java)
at java.net.InetAddress.getLocalHost(InetAddress.java:1623)
at Hi.main(Hi.java:8)

Was this page helpful?
0 / 5 - 0 ratings