--- old/src/java.base/share/classes/java/net/DatagramSocket.java 2019-12-17 14:39:09.000000000 +0000 +++ new/src/java.base/share/classes/java/net/DatagramSocket.java 2019-12-17 14:39:09.000000000 +0000 @@ -26,6 +26,7 @@ package java.net; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.channels.DatagramChannel; import java.security.AccessController; import java.security.PrivilegedExceptionAction; @@ -498,13 +499,17 @@ * if a security manager has been installed and it does * not permit access to the given remote address * + * @throws UncheckedIOException + * May be thrown by an implementation if connect fails, + * for example, if the destination address is non-routable + * * @see #disconnect */ public void connect(InetAddress address, int port) { try { connectInternal(address, port); } catch (SocketException se) { - throw new Error("connect failed", se); + throw new UncheckedIOException("connect failed", se); } } @@ -545,6 +550,14 @@ * Disconnects the socket. If the socket is closed or not connected, * then this method has no effect. * + * @apiNote If this method throws an UncheckedIOException, the socket + * may be left in an unspecified state. It is strongly recommended that + * the socket be closed when disconnect fails. + * + * @throws UncheckedIOException + * May be thrown by an implementation if it fails to dissolve the + * association and restore the socket to a consistent state. + * * @see #connect */ public void disconnect() { --- old/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java 2019-12-17 14:39:10.000000000 +0000 +++ new/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java 2019-12-17 14:39:09.000000000 +0000 @@ -26,6 +26,7 @@ package sun.nio.ch; import java.io.IOException; +import java.io.UncheckedIOException; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.VarHandle; @@ -106,7 +107,7 @@ try { connectInternal(new InetSocketAddress(address, port)); } catch (SocketException x) { - throw new Error(x); + throw new UncheckedIOException(x); } } @@ -122,7 +123,7 @@ try { dc.disconnect(); } catch (IOException x) { - throw new Error(x); + throw new UncheckedIOException(x); } }