Skip to content

Conversation

@copybara-service
Copy link

Add check if sun.misc.Unsafe is present but throws on use, to use the preexisting no-Unsafe paths if it does.

JavaProto is already robust in the absence of sun.misc.Unsafe, and checks for its existence via reflection to use as a performance optimization.

As part of the planned removal of sun.misc.Unsafe, a future JDK will have Unsafe available but most of the methods will throw by default, which would break JavaProto. This creates an odd situation that if it was removed we wouldn't break, but the intermediate turndown state does break us. By adding a usage of one method to see if it throws an UnsupportedOperationException, we avoid breaking users if they use Protobuf in this intermediate turndown state of the API (which will become the default state in a future JDK release).

It is still TBD whether a future release of Protobuf may stop using sun.misc.Unsafe always, or if we may keep this code alive for users running old JDKs; that detail is still TBD depending on performance implications.

#20760

@copybara-service copybara-service bot force-pushed the test_836682065 branch 2 times, most recently from 45c88f6 to 9282223 Compare November 25, 2025 17:44
… preexisting no-Unsafe paths if it does.

JavaProto is already robust in the absence of sun.misc.Unsafe, and checks for its existence via reflection to use as a performance optimization.

As part of the planned removal of sun.misc.Unsafe, a future JDK will have Unsafe available but most of the methods will throw by default, which would break JavaProto. This creates an odd situation that if it was removed we wouldn't break, but the intermediate turndown state does break us. By adding a usage of one method to see if it throws an UnsupportedOperationException, we avoid breaking users if they use Protobuf in this intermediate turndown state of the API (which will become the default state in a future JDK release).

It is still TBD whether a future release of Protobuf may stop using sun.misc.Unsafe always, or if we may keep this code alive for users running old JDKs; that detail is still TBD depending on performance implications.

#20760

PiperOrigin-RevId: 836715451
@copybara-service copybara-service bot merged commit 3514901 into main Nov 25, 2025
@copybara-service copybara-service bot deleted the test_836682065 branch November 25, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant