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

[GR-39473] java.lang.NoClassDefFoundError: com.sun.net.httpserver.HttpServer in runtime on JDK 17 #4671

Closed
tonivade opened this issue Jun 26, 2022 · 5 comments

Comments

@tonivade
Copy link

Describe the issue
Using com.sun.net.httpserver.HttpServer in native-image (JDK 17) throws NoClassDefFoundError with latest 22.2 dev version.
Version 22.1 it works as expected.

Steps to reproduce the issue
1.

import com.sun.net.httpserver.HttpServer;
import java.net.InetSocketAddress;
import java.io.IOException;

public class Test {
    public static void main(String[] args) throws IOException {
        var server = HttpServer.create(new InetSocketAddress("localhost", 8080), 10);
        System.out.println("starting server at localhost:8080");
        server.start();
    }
}
  1. javac Test.java
  2. native-image --no-fallback --allow-incomplete-classpath Test
  3. ./test
  4. NoClassDefFoundError

Describe GraalVM and your environment:
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment GraalVM CE 22.2.0-dev (build 17.0.4+7-jvmci-22.2-b04)
OpenJDK 64-Bit Server VM GraalVM CE 22.2.0-dev (build 17.0.4+7-jvmci-22.2-b04, mixed mode, sharing)

  • JDK major version: 17
  • OS: Linux
  • Architecture: AMD64

More details

 $ native-image --no-fallback --allow-incomplete-classpath Test
Warning: Using a deprecated option --allow-incomplete-classpath from command line. Allowing an incomplete classpath is now the default. Use --link-at-build-time to report linking errors at image build time for a class or package.
WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
========================================================================================================================
 $ ./test 
Exception in thread "main" java.lang.NoClassDefFoundError: com.sun.net.httpserver.HttpServer
        at Test.main(Test.java:7)
@fniephaus
Copy link
Member

Thanks for reporting a regression and providing a small reproducer, @tonivade! We'll look into a fix. As a workaround, the native executable works when you build with native-image --no-fallback -J--add-modules -JALL-SYSTEM Test.

@fniephaus fniephaus changed the title java.lang.NoClassDefFoundError: com.sun.net.httpserver.HttpServer in runtime on JDK 17 [GR-39473] java.lang.NoClassDefFoundError: com.sun.net.httpserver.HttpServer in runtime on JDK 17 Jun 27, 2022
@tonivade
Copy link
Author

Thanks for the workaround

sschuberth added a commit to oss-review-toolkit/ort that referenced this issue Jul 27, 2022
See [1].

[1]: oracle/graal#4671

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
sschuberth added a commit to oss-review-toolkit/ort that referenced this issue Jul 27, 2022
See [1].

[1]: oracle/graal#4671

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
@inez
Copy link

inez commented Sep 5, 2022

@fniephaus 's workaround expresses in Gradle (kts):

graalvmNative {
    binaries {
        named("main") {
            fallback.set(false)
            buildArgs.add("-J--add-modules")
            buildArgs.add("-JALL-SYSTEM")
        }
    }
}

@fniephaus fniephaus added this to the 22.3 milestone Sep 5, 2022
@fniephaus
Copy link
Member

This will be fixed in the 22.3 release. You can test it now using a dev build.

@tonivade
Copy link
Author

I can confirm it's working with the latest dev build.

Thanks a lot!

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

4 participants