-
Notifications
You must be signed in to change notification settings - Fork 15.5k
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
<Java> JDK 9 warning: Illegal reflective access by com.google.protobuf.UnsafeUtil to field java.nio.Buffer.address #3781
Comments
This is from the unsafe utility that we use in Google to optimize for performance without generating code. We are aware that the unsafe APIs are planned to be deprecated/removed since Java9 - thus this warning. The UnsafeUtil code is opensourced to show the usages of those APIs, and we are still working with the Java9 community to resolve the issue. That said, your project are not relying on the unsafe access, unless you explicitly call the unsafe APIs. The log is printed only because of the class initialization. |
Most major libraries have fixed this, or are working on it, protobuf should do the same: Tolerating warnings in logs is universally considered a bad practice. Java 9 has been GA for four months. |
@bartlomiej-dawidow Do you have a suggestion about how to fix the UnsafeUtil code? It's not clear to me whether there is an alternative that works on Java 7+ and doesn't trigger the Java 9 warning. |
Based on @pherl 's response the unsafe code is only used for optional optimizations and it is not needed for the library to work: So a natural fix would be to move that functionality to a separate Maven module, for example protobuf-java-unsafe. You could probably achieve the same effect with some class loader magic that would delay the problematic class's initialization until it is actually called. |
@bartlomiej-dawidow It's not a requirement at the moment, but will likely become one in the future. Separating the code or delay the initialization won't fix the issue. |
@xfxyjwf Do a multi-release jar: http://openjdk.java.net/jeps/238 - The main issue is how to wrangle bazel an acceptable fashion to make one of those, since the Java 9 version of the class will need to have the same name of com.google.protobuf.UnsafeUtils in a dir bazel doesn't natively support. |
@shemnon Thanks! That multi-release jar seems exactly what we need to provide support for both Java 9 and pre Java 9. I'll investigate how we can make use of it in protobuf. |
Hello! What's the status of work on the multi-release jar mentioned above? Thanks! |
It is Java 10 here and I'm still getting warnings!
|
trying to use Graal and definitely hit issues w/ unsafe usage. |
…arnings see: protocolbuffers/protobuf#3781 PiperOrigin-RevId: 208535953
n.b. The unsafe warning created by Protobuf is tracked protocolbuffers/protobuf#3781
It was pointed out to me that the |
This issue should be fixed at master with 624a40a#diff-6c9e043b78f78efc096211703bb7fa4a, which should be included in our next release. |
….UnsafeUtil Details are in protocolbuffers/protobuf#3781 Fixes warning WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:/home/user/experimental/protoc-gen-uml/target/universal/stage/lib/com.google.protobuf.protobuf-java-3.4.0.jar) to field java.nio.Buffer.address WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
G'day!
While testing one of our projects against JDK 9, the message below was printed to stderr. As it the message suggests, I'm now going on your nerves ;).
I've collected a few system details below and also a link to a file in your repo where I suspect the candidate that it complains about. If you can point me in a direction of how to solve it, I'm happy to contribute a PR.
As far as I can judge, the error message refers to this line here:
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java#L378
System specs:
The text was updated successfully, but these errors were encountered: