3

Class UnsafeByteOperations (3.19.4)

 1 year ago
source link: https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.UnsafeByteOperations
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Class UnsafeByteOperations (3.19.4)

bookmark_border

public final class UnsafeByteOperations

Provides a number of unsafe byte operations to be used by advanced applications with high performance requirements. These methods are referred to as "unsafe" due to the fact that they potentially expose the backing buffer of a ByteString to the application.

DISCLAIMER: The methods in this class should only be called if it is guaranteed that the buffer backing the ByteString will never change! Mutation of a ByteString can lead to unexpected and undesirable consequences in your application, and will likely be difficult to debug. Proceed with caution!

This can have a number of significant side affects that have spooky-action-at-a-distance-like behavior. In particular, if the bytes value changes out from under a Protocol Buffer:

  • serialization may throw
  • serialization may succeed but the wrong bytes may be written out
  • messages are no longer threadsafe
  • hashCode may be incorrect
    • can result in a permanent memory leak when used as a key in a long-lived HashMap
    • the semantics of many programs may be violated if this is the case

Each of these issues will occur in parts of the code base that are entirely distinct from the parts of the code base modifying the buffer. In fact, both parts of the code base may be correct

  • it is the bridging with the unsafe operations that was in error!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK