提交 36cde02e 编写于 作者: A alanb

7034155: (ch) NullPointerException in sun.io.ch.IOUtil when OOM is thrown

Reviewed-by: forax
上级 fa996007
...@@ -388,9 +388,8 @@ class DatagramChannelImpl ...@@ -388,9 +388,8 @@ class DatagramChannelImpl
// we must instead use a nonempty buffer, otherwise the call // we must instead use a nonempty buffer, otherwise the call
// will not block waiting for a datagram on some platforms. // will not block waiting for a datagram on some platforms.
int newSize = Math.max(rem, 1); int newSize = Math.max(rem, 1);
ByteBuffer bb = null; ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
try { try {
bb = Util.getTemporaryDirectBuffer(newSize);
int n = receiveIntoNativeBuffer(fd, bb, newSize, 0); int n = receiveIntoNativeBuffer(fd, bb, newSize, 0);
bb.flip(); bb.flip();
if (n > 0 && rem > 0) if (n > 0 && rem > 0)
...@@ -482,9 +481,8 @@ class DatagramChannelImpl ...@@ -482,9 +481,8 @@ class DatagramChannelImpl
assert (pos <= lim); assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0); int rem = (pos <= lim ? lim - pos : 0);
ByteBuffer bb = null; ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
try { try {
bb = Util.getTemporaryDirectBuffer(rem);
bb.put(src); bb.put(src);
bb.flip(); bb.flip();
// Do not update src until we see how many bytes were written // Do not update src until we see how many bytes were written
...@@ -766,10 +764,10 @@ class DatagramChannelImpl ...@@ -766,10 +764,10 @@ class DatagramChannelImpl
// check multicast address is compatible with this socket // check multicast address is compatible with this socket
if (group instanceof Inet4Address) { if (group instanceof Inet4Address) {
if (family == StandardProtocolFamily.INET6 && !Net.canIPv6SocketJoinIPv4Group()) if (family == StandardProtocolFamily.INET6 && !Net.canIPv6SocketJoinIPv4Group())
throw new IllegalArgumentException("Group is not IPv4 multicast address"); throw new IllegalArgumentException("IPv6 socket cannot join IPv4 multicast group");
} else if (group instanceof Inet6Address) { } else if (group instanceof Inet6Address) {
if (family != StandardProtocolFamily.INET6) if (family != StandardProtocolFamily.INET6)
throw new IllegalArgumentException("Group is not IPv6 multicast address"); throw new IllegalArgumentException("Only IPv6 sockets can join IPv6 multicast group");
} else { } else {
throw new IllegalArgumentException("Address type not supported"); throw new IllegalArgumentException("Address type not supported");
} }
......
...@@ -50,9 +50,8 @@ class IOUtil { ...@@ -50,9 +50,8 @@ class IOUtil {
int lim = src.limit(); int lim = src.limit();
assert (pos <= lim); assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0); int rem = (pos <= lim ? lim - pos : 0);
ByteBuffer bb = null; ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
try { try {
bb = Util.getTemporaryDirectBuffer(rem);
bb.put(src); bb.put(src);
bb.flip(); bb.flip();
// Do not update src until we see how many bytes were written // Do not update src until we see how many bytes were written
...@@ -187,9 +186,8 @@ class IOUtil { ...@@ -187,9 +186,8 @@ class IOUtil {
return readIntoNativeBuffer(fd, dst, position, nd, lock); return readIntoNativeBuffer(fd, dst, position, nd, lock);
// Substitute a native buffer // Substitute a native buffer
ByteBuffer bb = null; ByteBuffer bb = Util.getTemporaryDirectBuffer(dst.remaining());
try { try {
bb = Util.getTemporaryDirectBuffer(dst.remaining());
int n = readIntoNativeBuffer(fd, bb, position, nd, lock); int n = readIntoNativeBuffer(fd, bb, position, nd, lock);
bb.flip(); bb.flip();
if (n > 0) if (n > 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册