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

<Java> JDK 9 warning: Illegal reflective access by com.google.protobuf.UnsafeUtil to field java.nio.Buffer.address #3781

Closed
xenji opened this issue Oct 22, 2017 · 27 comments

Comments

@xenji
Copy link

xenji commented Oct 22, 2017

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


WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:/Users/mmueller/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-java/3.4.0/b32aba0cbe737a4ca953f71688725972e3ee927c/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
System specs:
System:
Darwin Brick 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_6

Java:
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

Gradle:
------------------------------------------------------------
Gradle 4.2.1
------------------------------------------------------------

Build time:   2017-10-02 15:36:21 UTC
Revision:     a88ebd6be7840c2e59ae4782eb0f27fbe3405ddf

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          9.0.1 (Oracle Corporation 9.0.1+11)
OS:           Mac OS X 10.13 x86_64
@liujisi
Copy link
Contributor

liujisi commented Oct 26, 2017

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.

@bartlomiej-dawidow
Copy link

Most major libraries have fixed this, or are working on it, protobuf should do the same:
netty/netty#7650
google/guice#1085

Tolerating warnings in logs is universally considered a bad practice. Java 9 has been GA for four months.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Jan 30, 2018

@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.

@bartlomiej-dawidow
Copy link

Based on @pherl 's response the unsafe code is only used for optional optimizations and it is not needed for the library to work:
#3781 (comment)

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.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Jan 30, 2018

@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.

@shemnon
Copy link

shemnon commented Feb 3, 2018

@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.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Feb 5, 2018

@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.

@xfxyjwf xfxyjwf reopened this Feb 5, 2018
@xfxyjwf xfxyjwf self-assigned this Feb 5, 2018
@outkaj
Copy link

outkaj commented Feb 27, 2018

Hello! What's the status of work on the multi-release jar mentioned above? Thanks!

@almothafar
Copy link

almothafar commented May 31, 2018

It is Java 10 here and I'm still getting warnings!
Any news?

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:.......) 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

@saturnism
Copy link

saturnism commented Jun 7, 2018

trying to use Graal and definitely hit issues w/ unsafe usage.

@ghost
Copy link

ghost commented Jan 3, 2019

This issue should be fixed at master with 624a40a#diff-6c9e043b78f78efc096211703bb7fa4a, which should be included in our next release.

@ghost ghost closed this as completed Jan 3, 2019
smartkiwi added a commit to smartkiwi/protoc-gen-uml that referenced this issue Sep 24, 2019
….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
This issue was closed.
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