Skip to content

Warnings about terminally deprecated Unsafe usage #20760

Open

Description

@fmeum

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

Activity

  1. added
    untriagedauto added to all issues by default when created.
    on Mar 20, 2025
  2. cushon commented on Mar 24, 2025

    @cushon
    Contributor

    (This is also tracked by internal bug b/382713504)

  3. added and removed
    untriagedauto added to all issues by default when created.
    on Mar 24, 2025
  4. github-actions commented on Sep 6, 2025

    @github-actions

    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.

  5. added
    inactiveDenotes the issue/PR has not seen activity in the last 90 days.
    on Sep 6, 2025
  6. fmeum commented on Sep 6, 2025

    @fmeum
    ContributorAuthor

    Still relevant (13 upvotes)

  7. added
    untriagedauto added to all issues by default when created.
    and removed
    inactiveDenotes the issue/PR has not seen activity in the last 90 days.
    on Sep 7, 2025
  8. danishnawab commented on Sep 17, 2025

    @danishnawab

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

  9. self-assigned this
    on Sep 17, 2025
  10. esrauchg commented on Sep 17, 2025

    @esrauchg
    Member

    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!

  11. bmarwell commented on Nov 18, 2025

    @bmarwell

    As a workaround (only to silence the warnings), you can add --sun-misc-unsafe-memory-access=allow for now.

  12. 34 remaining items

  13. esrauchg commented on Jun 10, 2026

    @esrauchg
    Member

    ETA July (we do quarterly minor cuts).

  14. cpovirk commented on Aug 3, 2026

    @cpovirk
    Contributor

    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.

  15. AGulev commented on Aug 21, 2026

    @AGulev

    ETA July (we do quarterly minor cuts).

    is it included into https://github.com/protocolbuffers/protobuf/releases/tag/v36.0 ?

    UPD: I think this one

    Stop using sun.misc.Unsafe in isValidUtf8 paths. (421d745)

  16. esrauchg commented on Aug 21, 2026

    @esrauchg
    Member

    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!

  17. AGulev commented on Aug 21, 2026

    @AGulev

    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!

    I've just update the lib: no more warnings. Thank you!

  18. added a commit that references this issue on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

javakeep openkeep inactive issues open for janitor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions