You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warnings about terminally deprecated Unsafe usage #20760
What version of protobuf and what language are you using?
Version: 30.1
Language: C++/Java/Python/C#/Ruby/PHP/Objective-C/Javascript
What operating system (Linux, Windows, ...) and version?
Any
What runtime / compiler are you using (e.g., python version or gcc version)
JDK 24
What did you do?
Use Protobuf generated messages.
What did you expect to see
No warnings
What did you see instead?
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.google.protobuf.UnsafeUtil$MemoryAccessor (file:/redacted/some.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.protobuf.UnsafeUtil$MemoryAccessor
WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
Anything else we should know about your project / environment
Reacted by Jules Jacobsen, Liam Miller-Cushon, Kim A. Betti, Danish Nawab, Asapha, Leonard Ehrenfried, Markus Gaisbauer, Yuri Govorushchenko, Vladimir Ikryanov, Vladyslav Lubenskyi and 77 more
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.
Reacted by Silviu BURCEA, Benjamin Marwell, Alexey Gulev, gongziyiyi, anthonyinfinity, Pavel Bludov, vstamate, Abdel, Nikolay Yurchenko, Daniel Burrell and 9 more
Sorry about failing to update the public issue here!
We're aware of this issue and are just resolving on which of a few possible paths to resolve it. We intend to resolve this before it should become a serious issue for any users, even early adopters of new JDKs.
Just to clarify the state a bit, JavaProto uses sun.misc.Unsafe as a performance optimization and supports environments where it is unavailable (checks existence via reflection and falls back to another), on that runtime it is only a performance slowdown in those environments.
It is not possible that JDK 26 will strictly remove it: the next step in the process is that 26 may change the behavior to throw by default instead of logging by default with a flag to opt back to logging. We understand that is currently more likely to happen in 27 or 28 however, but it has not been decided yet. In the worst case we could quickly do a patch release that tests if it throws and runs our fallback path with a printed notice that you may be slower unless you reenable it, but we also expect to have other temporary solutions that we could move fast on if it is announced that 26 is moving forward on this compared to 27 or 28 (compared to larger efforts that would also solve the problem a different way which we are still evaluating)
The next LTS will be 29 which we understand is almost certainly going to have the throw-by-default-but-flag-to-opt out behavior, and the actual removal of the API with no flag to opt back in will happen at some point after that LTS. We are obviously committed to fully resolving the topic well before that is a possibility.
Note that we also still officially support Java 8 until at least end of 2026, where Java 8 does not support any of the suggested replacement APIs for sun.misc.Unsafe. We are also correspondingly committed to still supporting Java 8 users.
Thanks!
Reacted by Liam Miller-Cushon, Ruslan S., Federico Tomassetti, Felix, Daniil Zulin, Niklas, Sean Arms, Silviu BURCEA, Nick Bathum, jonahmarkham-egandt and 8 more
I was reminded today that Robolectric tests use Lite protos (by design in google3, as I recall), leading to an error in a large fraction of internal Robolectric tests if we experiment with disabling Unsafe: java.lang.RuntimeException: Lite gencode is primarily intended for Android use and uses sun.misc.Unsafe which is not available in the current environment. To run in this environment, you may need to switch to standard gencode. I'm not sure if we could produce that error less aggressively or if there would need to be a deeper solution.
Activity
cushon commentedon Mar 24, 2025
(This is also tracked by internal bug b/382713504)
github-actions commentedon Sep 6, 2025
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled
inactivebecause the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.fmeum commentedon Sep 6, 2025
Still relevant (13 upvotes)
danishnawab commentedon Sep 17, 2025
@cushon can you share an update on the internal issue. Currently, it's only a warning but might become a runtime failure in JDK 26.
esrauchg commentedon Sep 17, 2025
Sorry about failing to update the public issue here!
We're aware of this issue and are just resolving on which of a few possible paths to resolve it. We intend to resolve this before it should become a serious issue for any users, even early adopters of new JDKs.
Just to clarify the state a bit, JavaProto uses sun.misc.Unsafe as a performance optimization and supports environments where it is unavailable (checks existence via reflection and falls back to another), on that runtime it is only a performance slowdown in those environments.
It is not possible that JDK 26 will strictly remove it: the next step in the process is that 26 may change the behavior to throw by default instead of logging by default with a flag to opt back to logging. We understand that is currently more likely to happen in 27 or 28 however, but it has not been decided yet. In the worst case we could quickly do a patch release that tests if it throws and runs our fallback path with a printed notice that you may be slower unless you reenable it, but we also expect to have other temporary solutions that we could move fast on if it is announced that 26 is moving forward on this compared to 27 or 28 (compared to larger efforts that would also solve the problem a different way which we are still evaluating)
The next LTS will be 29 which we understand is almost certainly going to have the throw-by-default-but-flag-to-opt out behavior, and the actual removal of the API with no flag to opt back in will happen at some point after that LTS. We are obviously committed to fully resolving the topic well before that is a possibility.
Note that we also still officially support Java 8 until at least end of 2026, where Java 8 does not support any of the suggested replacement APIs for sun.misc.Unsafe. We are also correspondingly committed to still supporting Java 8 users.
Thanks!
bmarwell commentedon Nov 18, 2025
As a workaround (only to silence the warnings), you can add
--sun-misc-unsafe-memory-access=allowfor now.Remove UnsafeDirectNioEncoder.
Add check if sun.misc.Unsafe is present but throws on use, to use the…
34 remaining items
esrauchg commentedon Jun 10, 2026
ETA July (we do quarterly minor cuts).
build: suppress sun.misc.Unsafe warnings from protobuf (envoyproxy#45315
cpovirk commentedon Aug 3, 2026
I was reminded today that Robolectric tests use Lite protos (by design in google3, as I recall), leading to an error in a large fraction of internal Robolectric tests if we experiment with disabling
Unsafe:java.lang.RuntimeException: Lite gencode is primarily intended for Android use and uses sun.misc.Unsafe which is not available in the current environment. To run in this environment, you may need to switch to standard gencode.I'm not sure if we could produce that error less aggressively or if there would need to be a deeper solution.Bazel: Suppress sun.misc.Unsafe warnings in JavaBuilder and Turbine
Suppress JDK 24+ sun.misc.Unsafe warning in forked asset compiler
Silence protobuf Unsafe warnings from Java TurbineDirect
Add JVM opts for the direct header compiler
Add header_compiler_direct_opts to java_toolchain
Add header_compiler_direct_opts to java_toolchain
Add a `java_toolchain` attribute to specify options to the `header_co…
AGulev commentedon Aug 21, 2026
is it included into https://github.com/protocolbuffers/protobuf/releases/tag/v36.0 ?
UPD: I think this one
esrauchg commentedon Aug 21, 2026
Yes, I went ahead and added an explicit callout about this to the release notes. Please do let us know if you see any issues. Thanks!
AGulev commentedon Aug 21, 2026
I've just update the lib: no more warnings. Thank you!
Bump protobuf to 36.0 (#30833)
Bump protobuf to 36.0 and rules_java to 9.9.0