summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2011-05-20 17:58:29 -0700
committerElliott Hughes <enh@google.com>2011-05-20 17:59:04 -0700
commita28bc96d63595a77fa918da8ccdda50e9eaae95e (patch)
tree3b4982608c7f15d6d1036c6dc6c99ef1569c6a12 /luni
parent2cff86c0c10588a35036fe5bbca83b07f53e1b1d (diff)
downloadlibcore-a28bc96d63595a77fa918da8ccdda50e9eaae95e.zip
libcore-a28bc96d63595a77fa918da8ccdda50e9eaae95e.tar.gz
libcore-a28bc96d63595a77fa918da8ccdda50e9eaae95e.tar.bz2
Fix read/write bugs in DatagramChannel and SocketChannel.
Also improve some exception detail messages for ease of debugging. These bugs were found by external/apache-harmony tests. Change-Id: I37a58c1d1f1c2150eb9171967f47ef9644e8ae15
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/nio/Buffer.java6
-rw-r--r--luni/src/main/java/java/nio/DatagramChannelImpl.java8
-rw-r--r--luni/src/main/java/java/nio/InvalidMarkException.java8
-rw-r--r--luni/src/main/java/java/nio/SocketChannelImpl.java8
4 files changed, 23 insertions, 7 deletions
diff --git a/luni/src/main/java/java/nio/Buffer.java b/luni/src/main/java/java/nio/Buffer.java
index c0ba368..bc152ef 100644
--- a/luni/src/main/java/java/nio/Buffer.java
+++ b/luni/src/main/java/java/nio/Buffer.java
@@ -303,7 +303,7 @@ public abstract class Buffer {
*/
void limitImpl(int newLimit) {
if (newLimit < 0 || newLimit > capacity) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Bad limit (capacity " + capacity + "): " + newLimit);
}
limit = newLimit;
@@ -355,7 +355,7 @@ public abstract class Buffer {
void positionImpl(int newPosition) {
if (newPosition < 0 || newPosition > limit) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Bad position (limit " + limit + "): " + newPosition);
}
position = newPosition;
@@ -383,7 +383,7 @@ public abstract class Buffer {
*/
public final Buffer reset() {
if (mark == UNSET_MARK) {
- throw new InvalidMarkException();
+ throw new InvalidMarkException("Mark not set");
}
position = mark;
return this;
diff --git a/luni/src/main/java/java/nio/DatagramChannelImpl.java b/luni/src/main/java/java/nio/DatagramChannelImpl.java
index 7874af6..a626857 100644
--- a/luni/src/main/java/java/nio/DatagramChannelImpl.java
+++ b/luni/src/main/java/java/nio/DatagramChannelImpl.java
@@ -262,7 +262,9 @@ class DatagramChannelImpl extends DatagramChannel implements FileDescriptorChann
begin();
int oldPosition = source.position();
sendCount = IoBridge.sendto(fd, source, 0, isa.getAddress(), isa.getPort());
- source.position(oldPosition + sendCount);
+ if (sendCount > 0) {
+ source.position(oldPosition + sendCount);
+ }
} finally {
end(sendCount >= 0);
}
@@ -353,7 +355,9 @@ class DatagramChannelImpl extends DatagramChannel implements FileDescriptorChann
}
int writeCount = writeImpl(src);
- src.position(src.position() + writeCount);
+ if (writeCount > 0) {
+ src.position(src.position() + writeCount);
+ }
return writeCount;
}
diff --git a/luni/src/main/java/java/nio/InvalidMarkException.java b/luni/src/main/java/java/nio/InvalidMarkException.java
index cb1050e..349cf3a 100644
--- a/luni/src/main/java/java/nio/InvalidMarkException.java
+++ b/luni/src/main/java/java/nio/InvalidMarkException.java
@@ -29,4 +29,12 @@ public class InvalidMarkException extends IllegalStateException {
*/
public InvalidMarkException() {
}
+
+ /**
+ * Constructs an {@code InvalidMarkException} with the given detail message.
+ * @hide
+ */
+ public InvalidMarkException(String detailMessage) {
+ super(detailMessage);
+ }
}
diff --git a/luni/src/main/java/java/nio/SocketChannelImpl.java b/luni/src/main/java/java/nio/SocketChannelImpl.java
index c659299..9f8c690 100644
--- a/luni/src/main/java/java/nio/SocketChannelImpl.java
+++ b/luni/src/main/java/java/nio/SocketChannelImpl.java
@@ -298,7 +298,9 @@ class SocketChannelImpl extends SocketChannel implements FileDescriptorChannel {
begin();
}
readCount = IoBridge.recvfrom(true, fd, dst, 0, null, false);
- dst.position(dst.position() + readCount);
+ if (readCount > 0) {
+ dst.position(dst.position() + readCount);
+ }
} finally {
if (isBlocking()) {
end(readCount > 0);
@@ -360,7 +362,9 @@ class SocketChannelImpl extends SocketChannel implements FileDescriptorChannel {
begin();
}
writeCount = IoBridge.sendto(fd, src, 0, null, 0);
- src.position(src.position() + writeCount);
+ if (writeCount > 0) {
+ src.position(src.position() + writeCount);
+ }
} finally {
if (isBlocking()) {
end(writeCount >= 0);