Fix ByteBuffer.put(ByteBuffer) edge case.
Replaced use of ByteBuffer.array() in ByteBuffer.put(ByteBuffer)
with a raw "hb" field access. This prevents .array() throwing a
ReadOnlyBufferException in case the buffer is a MappedByteBuffer
(only type of ByteBuffer without a backing array) and the put
argument is a non-empty, read-only HeapByteBuffer.
Removed the test from this cherry-pick to not cause CTS
issues.
Test: CtsLibcoreTestCases
Bug: 34045479
_______________________________
Change-Id: I59dcfab85c4ee6bc02f1f5dad4ad2f8de43dd991
(cherry picked from commit 094c77bee3cb096ab3cfe7a60729037d5add2e8e)
diff --git a/ojluni/src/main/java/java/nio/ByteBuffer.java b/ojluni/src/main/java/java/nio/ByteBuffer.java
index 523bbda..1e50922 100644
--- a/ojluni/src/main/java/java/nio/ByteBuffer.java
+++ b/ojluni/src/main/java/java/nio/ByteBuffer.java
@@ -555,14 +555,14 @@
// isDirect() doesn't imply !hasArray(), ByteBuffer.allocateDirect allocated buffer will
// have a backing, non-gc-movable byte array. JNI allocated direct byte buffers WILL NOT
// have a backing array.
- final Object srcObject = src.isDirect() ? src : src.array();
+ final Object srcObject = src.isDirect() ? src : src.hb;
int srcOffset = src.position();
if (!src.isDirect()) {
srcOffset += src.offset;
}
final ByteBuffer dst = this;
- final Object dstObject = dst.isDirect() ? dst : dst.array();
+ final Object dstObject = dst.isDirect() ? dst : dst.hb;
int dstOffset = dst.position();
if (!dst.isDirect()) {
dstOffset += dst.offset;