jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.82k stars 1.91k forks source link

NativeHelper triggers JDK warning #11826

Open cowwoc opened 3 months ago

cowwoc commented 3 months ago

Jetty version(s) 12.0.9

Jetty Environment core

Java version/vendor (use: java -version) openjdk 22.0.1 2024-04-16 OpenJDK Runtime Environment (build 22.0.1+8-16) OpenJDK 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing)

OS type/version Microsoft Windows [Version 10.0.19045.4412]

Description When starting a server, I get the following warning:

WARNING: A restricted method in java.lang.foreign.AddressLayout has been called
WARNING: java.lang.foreign.AddressLayout::withTargetLayout has been called by org.eclipse.jetty.quic.quiche.foreign.NativeHelper in an unnamed module
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

How to reproduce? Launch a new Server with HTTP/3 support

Expected behavior: Find a way to suppress this warning from within Jetty, or add a section to the programmer/operation guides explaining what to do.

In particular, I am wondering why we need to enable-native-access to ALL-UNNAMED. Shouldn't we be able to limit access to a specific Java Module?

lorban commented 3 months ago

Adding --enable-native-access=org.eclipse.jetty.quic.quiche.foreign should be enough. I'm not aware of any way to suppress that warning with code, but indeed, we could add a section to the documentation.

cowwoc commented 3 months ago

I just tried this and got WARNING: Unknown module: org.eclipse.jetty.quic.quiche.foreign specified to --enable-native-access which is weird given that this is the right module name. Maybe I need to pass this to the Maven compiler plugin instead of the top-level Maven process itself...

cowwoc commented 3 months ago

Hmm, nope. Passing this to the compiler does not work (error: invalid flag: --enable-native-access) which makes sense now that I think about it...

So it's not clear why this is failing. Per https://docs.oracle.com/en/java/javase/22/core/restricted-methods.html it should work the way you mentioned.

cowwoc commented 3 months ago

Nevermind, -DMAVEN_OPTS=--enable-native-access=org.eclipse.jetty.quic.quiche.foreign seems to work.

lorban commented 3 months ago

@sbordet where should that be reflected in the docs in your opinion?

cowwoc commented 3 months ago

My vote would be somewhere close to https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-server-http3-setup