--- old/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java 2019-10-30 11:36:56.000000000 +0000 +++ new/src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java 2019-10-30 11:36:56.000000000 +0000 @@ -404,6 +404,8 @@ private SocketAddress sender; // Set by receive0 (## ugh) + private static final int INITIAL = -100; // some unambiguous negative value + @Override public SocketAddress receive(ByteBuffer dst) throws IOException { if (dst.isReadOnly()) @@ -412,7 +414,7 @@ readLock.lock(); try { boolean blocking = isBlocking(); - int n = 0; + int n = INITIAL; ByteBuffer bb = null; try { SocketAddress remote = beginRead(blocking, false); @@ -450,7 +452,7 @@ } catch (SecurityException se) { // Ignore packet bb.clear(); - n = 0; + n = INITIAL; continue; } bb.flip(); @@ -463,7 +465,7 @@ } finally { if (bb != null) Util.releaseTemporaryDirectBuffer(bb); - endRead(blocking, n > 0); + endRead(blocking, n >= 0); assert IOStatus.check(n); } } finally {