Summary
Remove the following terminally deprecated methods from java.net.MulticastSocket
:
public void setTTL(byte ttl) throws IOException
public byte getTTL() throws IOException
public void send(DatagramPacket p, byte ttl) throws IOException
and the following terminally deprecated methods from java.net.DatagramSocketImpl
:
protected void setTTL(byte ttl) throws IOException
protected byte getTTL() throws IOException
Problem
The setTTL/getTTL
methods were deprecated in JDK 1.2 as byte
isn't sufficient to represent the range of possible time-to-live values. The @deprecated
message link to the replacement methods setTimeToLive/getTimeToLive
. The 2-arg send
method was deprecated in JDK 1.4 for the same reason. All 5 methods were deprecated for remove in JDK 23 (JDK-8332261). It is time to finally remove these methods.
Solution
Remove the 5 methods.
Specification
diff --git a/src/java.base/share/classes/java/net/DatagramSocketImpl.java b/src/java.base/share/classes/java/net/DatagramSocketImpl.java
- /**
- * Set the TTL (time-to-live) option.
- * @param ttl a byte specifying the TTL value
- *
- * @deprecated use setTimeToLive instead.
- * @throws IOException if an I/O exception occurs while setting
- * the time-to-live option.
- * @see #getTTL()
- */
- @Deprecated(forRemoval = true, since = "1.2")
- protected abstract void setTTL(byte ttl) throws IOException;
-
- /**
- * Retrieve the TTL (time-to-live) option.
- *
- * @throws IOException if an I/O exception occurs
- * while retrieving the time-to-live option
- * @deprecated use getTimeToLive instead.
- * @return a byte representing the TTL value
- * @see #setTTL(byte)
- */
- @Deprecated(forRemoval = true, since = "1.2")
- protected abstract byte getTTL() throws IOException;
-
diff --git a/src/java.base/share/classes/java/net/MulticastSocket.java b/src/java.base/share/classes/java/net/MulticastSocket.java
- /**
- * Set the default time-to-live for multicast packets sent out
- * on this {@code MulticastSocket} in order to control the
- * scope of the multicasts.
- *
- * <p>The ttl is an <b>unsigned</b> 8-bit quantity, and so <B>must</B> be
- * in the range {@code 0 <= ttl <= 0xFF }.
- *
- * @param ttl the time-to-live
- * @throws IOException if an I/O exception occurs
- * while setting the default time-to-live value, or the socket is closed.
- * @deprecated use the {@link #setTimeToLive(int)} method instead, which uses
- * <b>int</b> instead of <b>byte</b> as the type for ttl.
- * @see #getTTL()
- */
- @Deprecated(forRemoval = true, since = "1.2")
- public void setTTL(byte ttl) throws IOException {
- delegate().setTTL(ttl);
- }
-
- /**
- * Get the default time-to-live for multicast packets sent out on
- * the socket.
- *
- * @throws IOException if an I/O exception occurs
- * while getting the default time-to-live value, or the socket is closed.
- * @return the default time-to-live value
- * @deprecated use the {@link #getTimeToLive()} method instead,
- * which returns an <b>int</b> instead of a <b>byte</b>.
- * @see #setTTL(byte)
- */
- @Deprecated(forRemoval = true, since = "1.2")
- public byte getTTL() throws IOException {
- return delegate().getTTL();
- }
-
- /**
- * Sends a datagram packet to the destination, with a TTL (time-to-live)
- * other than the default for the socket. This method
- * need only be used in instances where a particular TTL is desired;
- * otherwise it is preferable to set a TTL once on the socket, and
- * use that default TTL for all packets. This method does <B>not
- * </B> alter the default TTL for the socket. Its behavior may be
- * affected by {@code setInterface}.
- *
- * @param p is the packet to be sent. The packet should contain
- * the destination multicast ip address and the data to be sent.
- * One does not need to be the member of the group to send
- * packets to a destination multicast address.
- * @param ttl optional time to live for multicast packet.
- * default ttl is 1.
- *
- * @throws IOException if an I/O error occurs, or the socket is closed.
- * @throws PortUnreachableException may be thrown if the socket is connected
- * to a currently unreachable destination. Note, there is no
- * guarantee that the exception will be thrown.
- * @throws IllegalArgumentException if the socket is connected,
- * and connected address and packet address differ, or
- * if the socket is not connected and the packet address
- * is not set or if its port is out of range.
- *
- *
- * @deprecated Use the following code or its equivalent instead:
- * <pre>{@code ......
- * int ttl = mcastSocket.getOption(StandardSocketOptions.IP_MULTICAST_TTL);
- * mcastSocket.setOption(StandardSocketOptions.IP_MULTICAST_TTL, newttl);
- * mcastSocket.send(p);
- * mcastSocket.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);
- * ......}</pre>
- *
- * @see DatagramSocket#send
- * @see DatagramSocket#receive
- */
- @Deprecated(forRemoval = true, since = "1.4")
- public void send(DatagramPacket p, byte ttl)
- throws IOException {
- delegate().send(p, ttl);
- }
- csr of
-
JDK-8332623 Remove setTTL()/getTTL() methods from DatagramSocketImpl/MulticastSocket and MulticastSocket.send(DatagramPacket, byte)
-
- Resolved
-