From f7cd3fad2400cd3a07d8a3a44d86d5dc4d23913e Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Tue, 17 Jun 2025 08:32:17 +0000 Subject: [PATCH] 8332623: Remove setTTL()/getTTL() methods from DatagramSocketImpl/MulticastSocket and MulticastSocket.send(DatagramPacket, byte) Reviewed-by: dfuchs, alanb --- .../classes/java/net/DatagramSocketImpl.java | 26 +----- .../classes/java/net/MulticastSocket.java | 81 +------------------ .../classes/java/net/NetMulticastSocket.java | 70 +--------------- .../sun/nio/ch/DatagramSocketAdaptor.java | 47 +---------- .../net/DatagramSocket/AddressNotSet.java | 40 +-------- .../DatagramSocketMulticasting.java | 4 +- .../OldDatagramSocketImplTest.java | 10 +-- .../java/net/DatagramSocket/SendCheck.java | 16 +--- .../java/net/MyDatagramSocketImplFactory.java | 11 +-- .../net/DatagramSocketImpl/TestCreate.java | 4 +- .../TestDefaultBehavior.java | 4 +- .../net/MulticastSocket/MulticastTTL.java | 61 -------------- .../net/MulticastSocket/SendPortZero.java | 3 +- .../MulticastSocket/SetLoopbackOption.java | 12 +-- .../net/MulticastSocket/SetTTLAndGetTTL.java | 48 ----------- .../java/net/MulticastSocket/SetTTLTo0.java | 3 +- .../net/SocketOption/CachedImplOptions.java | 4 +- .../net/SocketOption/ImmutableOptions.java | 6 +- .../DatagramChannel/AdaptorMulticasting.java | 20 +---- 19 files changed, 25 insertions(+), 445 deletions(-) delete mode 100644 test/jdk/java/net/MulticastSocket/MulticastTTL.java delete mode 100644 test/jdk/java/net/MulticastSocket/SetTTLAndGetTTL.java diff --git a/src/java.base/share/classes/java/net/DatagramSocketImpl.java b/src/java.base/share/classes/java/net/DatagramSocketImpl.java index 54093a9d5f1..71db2c0a427 100644 --- a/src/java.base/share/classes/java/net/DatagramSocketImpl.java +++ b/src/java.base/share/classes/java/net/DatagramSocketImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -162,30 +162,6 @@ public abstract class DatagramSocketImpl implements SocketOptions { */ protected abstract void receive(DatagramPacket p) throws IOException; - /** - * 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; - /** * Set the TTL (time-to-live) option. * @param ttl an {@code int} specifying the time-to-live value diff --git a/src/java.base/share/classes/java/net/MulticastSocket.java b/src/java.base/share/classes/java/net/MulticastSocket.java index 367aaf3a9ea..ac1b40c2767 100644 --- a/src/java.base/share/classes/java/net/MulticastSocket.java +++ b/src/java.base/share/classes/java/net/MulticastSocket.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -188,26 +188,6 @@ public class MulticastSocket extends DatagramSocket { this(createDelegate(bindaddr, MulticastSocket.class)); } - /** - * Set the default time-to-live for multicast packets sent out - * on this {@code MulticastSocket} in order to control the - * scope of the multicasts. - * - *

The ttl is an unsigned 8-bit quantity, and so must 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 - * int instead of byte as the type for ttl. - * @see #getTTL() - */ - @Deprecated(forRemoval = true, since = "1.2") - public void setTTL(byte ttl) throws IOException { - delegate().setTTL(ttl); - } - /** * Set the default time-to-live for multicast packets sent out * on this {@code MulticastSocket} in order to control the @@ -237,22 +217,6 @@ public class MulticastSocket extends DatagramSocket { delegate().setTimeToLive(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 int instead of a byte. - * @see #setTTL(byte) - */ - @Deprecated(forRemoval = true, since = "1.2") - public byte getTTL() throws IOException { - return delegate().getTTL(); - } - /** * Get the default time-to-live for multicast packets sent out on * the socket. @@ -466,47 +430,4 @@ public class MulticastSocket extends DatagramSocket { public boolean getLoopbackMode() throws SocketException { return delegate().getLoopbackMode(); } - - /** - * 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 not - * 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: - *

{@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);
-     *  ......}
- * - * @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); - } } diff --git a/src/java.base/share/classes/java/net/NetMulticastSocket.java b/src/java.base/share/classes/java/net/NetMulticastSocket.java index bce2e945335..80cb997102f 100644 --- a/src/java.base/share/classes/java/net/NetMulticastSocket.java +++ b/src/java.base/share/classes/java/net/NetMulticastSocket.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -567,12 +567,6 @@ final class NetMulticastSocket extends MulticastSocket { */ private boolean interfaceSet; - /** - * The lock on the socket's TTL. This is for set/getTTL and - * send(packet,ttl). - */ - private final Object ttlLock = new Object(); - /** * The lock on the socket's interface - used by setInterface * and getInterface @@ -584,14 +578,6 @@ final class NetMulticastSocket extends MulticastSocket { */ private InetAddress infAddress = null; - @Override - @SuppressWarnings("removal") - public void setTTL(byte ttl) throws IOException { - if (isClosed()) - throw new SocketException("Socket is closed"); - getImpl().setTTL(ttl); - } - @Override public void setTimeToLive(int ttl) throws IOException { if (ttl < 0 || ttl > 255) { @@ -602,14 +588,6 @@ final class NetMulticastSocket extends MulticastSocket { getImpl().setTimeToLive(ttl); } - @Override - @SuppressWarnings("removal") - public byte getTTL() throws IOException { - if (isClosed()) - throw new SocketException("Socket is closed"); - return getImpl().getTTL(); - } - @Override public int getTimeToLive() throws IOException { if (isClosed()) @@ -796,50 +774,4 @@ final class NetMulticastSocket extends MulticastSocket { public boolean getLoopbackMode() throws SocketException { return ((Boolean)getImpl().getOption(SocketOptions.IP_MULTICAST_LOOP)).booleanValue(); } - - @SuppressWarnings("removal") - @Override - public void send(DatagramPacket p, byte ttl) - throws IOException { - if (isClosed()) - throw new SocketException("Socket is closed"); - synchronized(ttlLock) { - synchronized(p) { - InetAddress packetAddress = p.getAddress(); - checkAddress(packetAddress, "send"); - if (connectState == ST_NOT_CONNECTED) { - if (packetAddress == null) { - throw new IllegalArgumentException("Address not set"); - } - } else { - // we're connected - if (packetAddress == null) { - p.setAddress(connectedAddress); - p.setPort(connectedPort); - } else if ((!packetAddress.equals(connectedAddress)) || - p.getPort() != connectedPort) { - throw new IllegalArgumentException("connected address and packet address" + - " differ"); - } - } - byte dttl = getTTL(); - try { - if (ttl != dttl) { - // set the ttl - getImpl().setTTL(ttl); - } - if (p.getPort() == 0) { - throw new SocketException("Can't send to port 0"); - } - // call the datagram method to send - getImpl().send(p); - } finally { - // set it back to default - if (ttl != dttl) { - getImpl().setTTL(dttl); - } - } - } // synch p - } //synch ttl - } //method } diff --git a/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java b/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java index 44b05f97472..a9962d19400 100644 --- a/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java +++ b/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java @@ -50,7 +50,6 @@ import java.nio.channels.DatagramChannel; import java.nio.channels.MembershipKey; import java.util.Objects; import java.util.Set; -import java.util.concurrent.locks.ReentrantLock; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static jdk.internal.util.Exceptions.formatMsg; @@ -372,44 +371,19 @@ public class DatagramSocketAdaptor // -- java.net.MulticastSocket -- - // used to coordinate changing TTL with the deprecated send method - private final ReentrantLock sendLock = new ReentrantLock(); - // cached outgoing interface (for use by setInterface/getInterface) private final Object outgoingInterfaceLock = new Object(); private NetworkInterface outgoingNetworkInterface; private InetAddress outgoingInetAddress; - @Override - @SuppressWarnings("removal") - public void setTTL(byte ttl) throws IOException { - setTimeToLive(Byte.toUnsignedInt(ttl)); - } - @Override public void setTimeToLive(int ttl) throws IOException { - sendLock.lock(); - try { - setIntOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl); - } finally { - sendLock.unlock(); - } - } - - @Override - @SuppressWarnings("removal") - public byte getTTL() throws IOException { - return (byte) getTimeToLive(); + setIntOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl); } @Override public int getTimeToLive() throws IOException { - sendLock.lock(); - try { - return getIntOption(StandardSocketOptions.IP_MULTICAST_TTL); - } finally { - sendLock.unlock(); - } + return getIntOption(StandardSocketOptions.IP_MULTICAST_TTL); } @Override @@ -558,23 +532,6 @@ public class DatagramSocketAdaptor return !enabled; } - @Override - @SuppressWarnings("removal") - public void send(DatagramPacket p, byte ttl) throws IOException { - sendLock.lock(); - try { - int oldValue = getTimeToLive(); - try { - setTTL(ttl); - send(p); - } finally { - setTimeToLive(oldValue); - } - } finally { - sendLock.unlock(); - } - } - /** * Returns the outgoing NetworkInterface or null if not set. */ diff --git a/test/jdk/java/net/DatagramSocket/AddressNotSet.java b/test/jdk/java/net/DatagramSocket/AddressNotSet.java index 0e7b28aa044..afab2c686d1 100644 --- a/test/jdk/java/net/DatagramSocket/AddressNotSet.java +++ b/test/jdk/java/net/DatagramSocket/AddressNotSet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -108,43 +108,5 @@ public class AddressNotSet { p = new DatagramPacket(buf, buf.length, addr, port); sock.send(p); serversock.receive(p); - - if (sock instanceof MulticastSocket) { - sock.disconnect(); - testTTL((MulticastSocket)sock); - } - } - - private void testTTL(MulticastSocket sock) throws Exception { - out.println("Testing deprecated send TTL with " + sock.getClass()); - final byte ttl = 100; - InetAddress addr = loopbackAddress; - byte[] buf; - DatagramPacket p; - int port = serversock.getLocalPort(); - - out.println("Checking send to non-connected address ..."); - try { - out.println("Checking send with no packet address"); - buf = ("Hello, server"+(++i)).getBytes(); - p = new DatagramPacket(buf, buf.length); - sock.send(p,ttl); - throw new AssertionError("Expected IllegalArgumentException not received"); - } catch (IllegalArgumentException x) { - out.println("Got expected exception: " + x); - } - - out.println("Connecting to connected address: " + sock); - sock.connect(addr, port); - - try { - out.println("Checking send with different address than connected"); - buf = ("Hello, server"+(++i)).getBytes(); - p = new DatagramPacket(buf, buf.length, addr, port+1); - sock.send(p, ttl); - throw new AssertionError("Expected IllegalArgumentException not received"); - } catch (IllegalArgumentException x) { - out.println("Got expected exception: " + x); - } } } diff --git a/test/jdk/java/net/DatagramSocket/DatagramSocketMulticasting.java b/test/jdk/java/net/DatagramSocket/DatagramSocketMulticasting.java index 1758ff2190c..39cdf7210f7 100644 --- a/test/jdk/java/net/DatagramSocket/DatagramSocketMulticasting.java +++ b/test/jdk/java/net/DatagramSocket/DatagramSocketMulticasting.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -252,7 +252,7 @@ public class DatagramSocketMulticasting { } /** - * Test getTimeToLive/setTimeToLive/getTTL/getTTL and IP_MULTICAST_TTL socket + * Test getTimeToLive/setTimeToLive and IP_MULTICAST_TTL socket * option. */ static void testTimeToLive(DatagramSocket s) throws IOException { diff --git a/test/jdk/java/net/DatagramSocket/OldDatagramSocketImplTest.java b/test/jdk/java/net/DatagramSocket/OldDatagramSocketImplTest.java index c1a110c6619..7f8eea874ec 100644 --- a/test/jdk/java/net/DatagramSocket/OldDatagramSocketImplTest.java +++ b/test/jdk/java/net/DatagramSocket/OldDatagramSocketImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -121,14 +121,6 @@ public class OldDatagramSocketImplTest { @Override protected void receive(DatagramPacket p) throws IOException { } - @Override - protected void setTTL(byte ttl) throws IOException { } - - @Override - protected byte getTTL() throws IOException { - return 0; - } - @Override protected void setTimeToLive(int ttl) throws IOException { } diff --git a/test/jdk/java/net/DatagramSocket/SendCheck.java b/test/jdk/java/net/DatagramSocket/SendCheck.java index 8943e8517fa..482eadb3cf9 100644 --- a/test/jdk/java/net/DatagramSocket/SendCheck.java +++ b/test/jdk/java/net/DatagramSocket/SendCheck.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,7 +45,7 @@ import static org.testng.Assert.expectThrows; * @bug 8236105 * @summary Check that DatagramSocket, MulticastSocket, * DatagramSocketAdaptor and DatagramChannel all - * throw expected Execption when passed a DatagramPacket + * throw expected Exception when passed a DatagramPacket * with invalid details * @run testng SendCheck */ @@ -126,11 +126,9 @@ public class SendCheck { List senders = List.of( Sender.of(new DatagramSocket(null)), - Sender.of(new MulticastSocket(null), (byte) 0), + Sender.of(new MulticastSocket(null)), Sender.of(DatagramChannel.open()), - Sender.of(DatagramChannel.open().socket()), - Sender.of((MulticastSocket) - DatagramChannel.open().socket(), (byte) 0) + Sender.of(DatagramChannel.open().socket()) ); List testcases = new ArrayList<>(); @@ -179,12 +177,6 @@ public class SendCheck { return new SenderImpl<>(socket, socket::send, socket::close, SE); } - static Sender of(MulticastSocket socket, byte ttl) { - SenderImpl.Send send = - (pkt) -> socket.send(pkt, ttl); - return new SenderImpl<>(socket, send, socket::close, SE); - } - static Sender of(DatagramChannel socket) { SenderImpl.Send send = (pkt) -> socket.send(ByteBuffer.wrap(pkt.getData()), diff --git a/test/jdk/java/net/DatagramSocket/SetDatagramSocketImplFactory/java.base/java/net/MyDatagramSocketImplFactory.java b/test/jdk/java/net/DatagramSocket/SetDatagramSocketImplFactory/java.base/java/net/MyDatagramSocketImplFactory.java index 41a209ccf01..41f1a33a817 100644 --- a/test/jdk/java/net/DatagramSocket/SetDatagramSocketImplFactory/java.base/java/net/MyDatagramSocketImplFactory.java +++ b/test/jdk/java/net/DatagramSocket/SetDatagramSocketImplFactory/java.base/java/net/MyDatagramSocketImplFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -63,15 +63,6 @@ public class MyDatagramSocketImplFactory implements DatagramSocketImplFactory { ds.receive(p); } - @Override - protected void setTTL(byte ttl) throws IOException { - } - - @Override - protected byte getTTL() throws IOException { - return 0; - } - @Override protected void setTimeToLive(int ttl) throws IOException { diff --git a/test/jdk/java/net/DatagramSocketImpl/TestCreate.java b/test/jdk/java/net/DatagramSocketImpl/TestCreate.java index 5a0fdf63283..81772074ae2 100644 --- a/test/jdk/java/net/DatagramSocketImpl/TestCreate.java +++ b/test/jdk/java/net/DatagramSocketImpl/TestCreate.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -105,8 +105,6 @@ public class TestCreate { @Override protected int peek(InetAddress i) { return 0; } @Override protected int peekData(DatagramPacket p) { return 0; } @Override protected void receive(DatagramPacket p) { } - @Override protected void setTTL(byte ttl) { } - @Override protected byte getTTL() { return 0; } @Override protected void setTimeToLive(int ttl) { } @Override protected int getTimeToLive() { return 0; } @Override protected void join(InetAddress inetaddr) { } diff --git a/test/jdk/java/net/DatagramSocketImpl/TestDefaultBehavior.java b/test/jdk/java/net/DatagramSocketImpl/TestDefaultBehavior.java index 760f7586c27..2e223f1820c 100644 --- a/test/jdk/java/net/DatagramSocketImpl/TestDefaultBehavior.java +++ b/test/jdk/java/net/DatagramSocketImpl/TestDefaultBehavior.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -99,8 +99,6 @@ public class TestDefaultBehavior { @Override protected int peek(InetAddress i) { return 0; } @Override protected int peekData(DatagramPacket p) { return 0; } @Override protected void receive(DatagramPacket p) { } - @Override protected void setTTL(byte ttl) { } - @Override protected byte getTTL() { return 0; } @Override protected void setTimeToLive(int ttl) { } @Override protected int getTimeToLive() { return 0; } @Override protected void join(InetAddress inetaddr) { } diff --git a/test/jdk/java/net/MulticastSocket/MulticastTTL.java b/test/jdk/java/net/MulticastSocket/MulticastTTL.java deleted file mode 100644 index 0fcc5a373d4..00000000000 --- a/test/jdk/java/net/MulticastSocket/MulticastTTL.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 4089415 - * @summary Test MulticastSocket send for modification of ttl - * - */ -import java.io.*; -import java.net.*; - -public class MulticastTTL { - - public static void main(String args[]) throws Exception { - MulticastSocket soc = null; - DatagramPacket pac = null; - InetAddress sin = null; - byte [] array = new byte[65537]; - int port = 0; - byte old_ttl = 0; - byte new_ttl = 64; - byte ttl = 0; - - sin = InetAddress.getByName("224.80.80.80"); - soc = new MulticastSocket(); - port = soc.getLocalPort(); - old_ttl = soc.getTTL(); - pac = new DatagramPacket(array, array.length, sin, port); - - try { - soc.send(pac, new_ttl); - } catch(java.io.IOException e) { - ttl = soc.getTTL(); - soc.close(); - if(ttl != old_ttl) - throw new RuntimeException("TTL "); - } - soc.close(); - } -} diff --git a/test/jdk/java/net/MulticastSocket/SendPortZero.java b/test/jdk/java/net/MulticastSocket/SendPortZero.java index 2155cf4149f..0d8acd86c8c 100644 --- a/test/jdk/java/net/MulticastSocket/SendPortZero.java +++ b/test/jdk/java/net/MulticastSocket/SendPortZero.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -93,7 +93,6 @@ public class SendPortZero { @Test(dataProvider = "data") public void testSend(MulticastSocket ms, DatagramPacket pkt) { assertThrows(SE, () -> ms.send(pkt)); - assertThrows(SE, () -> ms.send(pkt, (byte) 0)); } @AfterTest diff --git a/test/jdk/java/net/MulticastSocket/SetLoopbackOption.java b/test/jdk/java/net/MulticastSocket/SetLoopbackOption.java index 7e39e6fc013..ed831cfbdf7 100644 --- a/test/jdk/java/net/MulticastSocket/SetLoopbackOption.java +++ b/test/jdk/java/net/MulticastSocket/SetLoopbackOption.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -206,16 +206,6 @@ public class SetLoopbackOption { shouldNotComeHere(); } - @Override - protected void setTTL(byte ttl) throws IOException { - shouldNotComeHere(); - } - - @Override - protected byte getTTL() throws IOException { - return shouldNotComeHere(); - } - @Override protected void setTimeToLive(int ttl) throws IOException { shouldNotComeHere(); diff --git a/test/jdk/java/net/MulticastSocket/SetTTLAndGetTTL.java b/test/jdk/java/net/MulticastSocket/SetTTLAndGetTTL.java deleted file mode 100644 index ba07dc57dfd..00000000000 --- a/test/jdk/java/net/MulticastSocket/SetTTLAndGetTTL.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* @test - * @bug 4189640 - * @summary Make setTTL/getTTL works - * @run main SetTTLAndGetTTL - */ - -import java.net.*; - -public class SetTTLAndGetTTL { - - public static void main(String args[]) throws Exception { - MulticastSocket soc = null; - - try { - soc = new MulticastSocket(); - } catch(Exception e) { - throw new Exception("Unexpected Exception"); - } - - soc.setTTL((byte)200); - byte ttlValue = soc.getTTL(); - if (ttlValue != (byte)200) - throw new Exception("setTTL/getTTL is broken"); - } -} diff --git a/test/jdk/java/net/MulticastSocket/SetTTLTo0.java b/test/jdk/java/net/MulticastSocket/SetTTLTo0.java index 8bb4184081a..68dc8c43bc9 100644 --- a/test/jdk/java/net/MulticastSocket/SetTTLTo0.java +++ b/test/jdk/java/net/MulticastSocket/SetTTLTo0.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,7 +40,6 @@ public class SetTTLTo0 { throw new Exception("Unexpected Exception"); } - soc.setTTL((byte)0); soc.setTimeToLive(0); } diff --git a/test/jdk/java/net/SocketOption/CachedImplOptions.java b/test/jdk/java/net/SocketOption/CachedImplOptions.java index ed2c2a9ebdf..955414559c2 100644 --- a/test/jdk/java/net/SocketOption/CachedImplOptions.java +++ b/test/jdk/java/net/SocketOption/CachedImplOptions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -124,8 +124,6 @@ public class CachedImplOptions { @Override protected int peek(InetAddress i) { return 0; } @Override protected int peekData(DatagramPacket p) { return 0; } @Override protected void receive(DatagramPacket p) { } - @Override protected void setTTL(byte ttl) { } - @Override protected byte getTTL() { return 0; } @Override protected void setTimeToLive(int ttl) { } @Override protected int getTimeToLive() { return 0; } @Override protected void join(InetAddress inetaddr) { } diff --git a/test/jdk/java/net/SocketOption/ImmutableOptions.java b/test/jdk/java/net/SocketOption/ImmutableOptions.java index 4a2e4419f9d..f15734edddc 100644 --- a/test/jdk/java/net/SocketOption/ImmutableOptions.java +++ b/test/jdk/java/net/SocketOption/ImmutableOptions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -162,10 +162,6 @@ public class ImmutableOptions { protected void receive(DatagramPacket p) throws IOException { } - protected void setTTL(byte ttl) throws IOException { } - - protected byte getTTL() throws IOException { return 0; } - protected void setTimeToLive(int ttl) throws IOException { } protected int getTimeToLive() throws IOException { return 0; } diff --git a/test/jdk/java/nio/channels/DatagramChannel/AdaptorMulticasting.java b/test/jdk/java/nio/channels/DatagramChannel/AdaptorMulticasting.java index cab2bc76285..4cb9be7efe9 100644 --- a/test/jdk/java/nio/channels/DatagramChannel/AdaptorMulticasting.java +++ b/test/jdk/java/nio/channels/DatagramChannel/AdaptorMulticasting.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -327,39 +327,27 @@ public class AdaptorMulticasting { } /** - * Test getTimeToLive/setTimeToLive/getTTL/getTTL and IP_MULTICAST_TTL socket + * Test getTimeToLive/setTimeToLive and IP_MULTICAST_TTL socket * option. */ static void testTimeToLive(MulticastSocket s) throws IOException { // should be 1 by default assertTrue(s.getTimeToLive() == 1); - assertTrue(s.getTTL() == 1); assertTrue(s.getOption(IP_MULTICAST_TTL) == 1); // setTimeToLive for (int ttl = 0; ttl <= 2; ttl++) { s.setTimeToLive(ttl); assertTrue(s.getTimeToLive() == ttl); - assertTrue(s.getTTL() == ttl); assertTrue(s.getOption(IP_MULTICAST_TTL) == ttl); } assertThrows(IllegalArgumentException.class, () -> s.setTimeToLive(-1)); - // setTTL - for (byte ttl = (byte) -2; ttl <= 2; ttl++) { - s.setTTL(ttl); - assertTrue(s.getTTL() == ttl); - int intValue = Byte.toUnsignedInt(ttl); - assertTrue(s.getTimeToLive() == intValue); - assertTrue(s.getOption(IP_MULTICAST_TTL) == intValue); - } - // setOption(IP_MULTICAST_TTL) for (int ttl = 0; ttl <= 2; ttl++) { s.setOption(IP_MULTICAST_TTL, ttl); assertTrue(s.getOption(IP_MULTICAST_TTL) == ttl); assertTrue(s.getTimeToLive() == ttl); - assertTrue(s.getTTL() == ttl); } // bad values for IP_MULTICAST_TTL @@ -419,7 +407,7 @@ public class AdaptorMulticasting { // send message to multicast group DatagramPacket p = new DatagramPacket(message, message.length); p.setSocketAddress(target); - s.send(p, (byte) 1); + s.send(p); // receive message s.setSoTimeout(0); @@ -463,7 +451,7 @@ public class AdaptorMulticasting { // send datagram to multicast group DatagramPacket p = new DatagramPacket(message, message.length); p.setSocketAddress(target); - s.send(p, (byte) 1); + s.send(p); // datagram should not be received s.setSoTimeout(500);