summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
authorLajos Molnar <lajos@google.com>2014-05-16 17:08:53 -0700
committerLajos Molnar <lajos@google.com>2014-05-16 17:17:53 -0700
commite30eaf6894647ecf5e1ec3ec5ac8221e41b4d170 (patch)
treee6aa3e6e588b9d1389355a81369a0124f5e36962 /luni/src
parentc58e40aa931b136cd54b6592bdba1d10592d8687 (diff)
downloadlibcore-e30eaf6894647ecf5e1ec3ec5ac8221e41b4d170.zip
libcore-e30eaf6894647ecf5e1ec3ec5ac8221e41b4d170.tar.gz
libcore-e30eaf6894647ecf5e1ec3ec5ac8221e41b4d170.tar.bz2
DirectByteBuffer: allow 0-size MappedByteBuffers starting at NULL
Bug: 14297827 Change-Id: I53ae796f9a59c70cc8250477ab51c57ea728e43b
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/main/java/java/nio/MemoryBlock.java5
-rw-r--r--luni/src/test/java/libcore/java/nio/BufferTest.java2
2 files changed, 5 insertions, 2 deletions
diff --git a/luni/src/main/java/java/nio/MemoryBlock.java b/luni/src/main/java/java/nio/MemoryBlock.java
index a619b8d..b62e3c6 100644
--- a/luni/src/main/java/java/nio/MemoryBlock.java
+++ b/luni/src/main/java/java/nio/MemoryBlock.java
@@ -95,6 +95,7 @@ class MemoryBlock {
protected long address;
protected final long size;
private boolean accessible;
+ private boolean freed;
public static MemoryBlock mmap(FileDescriptor fd, long offset, long size, MapMode mapMode) throws IOException {
if (size == 0) {
@@ -140,6 +141,7 @@ class MemoryBlock {
this.address = address;
this.size = size;
accessible = true;
+ freed = false;
}
// Used to support array/arrayOffset/hasArray for direct buffers.
@@ -149,10 +151,11 @@ class MemoryBlock {
public void free() {
address = 0;
+ freed = true;
}
public boolean isFreed() {
- return address == 0;
+ return freed;
}
public boolean isAccessible() {
diff --git a/luni/src/test/java/libcore/java/nio/BufferTest.java b/luni/src/test/java/libcore/java/nio/BufferTest.java
index de4e0f1..613c6fa 100644
--- a/luni/src/test/java/libcore/java/nio/BufferTest.java
+++ b/luni/src/test/java/libcore/java/nio/BufferTest.java
@@ -731,7 +731,7 @@ public class BufferTest extends TestCase {
Class<?> c = Class.forName("java.nio.DirectByteBuffer");
Constructor<?> ctor = c.getDeclaredConstructor(long.class, int.class);
ctor.setAccessible(true);
- ByteBuffer bb = (ByteBuffer) ctor.newInstance(1, 0);
+ ByteBuffer bb = (ByteBuffer) ctor.newInstance(0, 0);
try {
bb.array();