test/jdk/java/net/DatagramSocket/AddressNotSet.java
author dfuchs
Mon, 18 Nov 2019 16:48:05 +0000
changeset 59124 d01fe40e9cd8
permissions -rw-r--r--
8233141: DatagramSocket.send doesn't specify exception thrown when no target address Summary: DatagramSocket and MulticastSocket send methods are changed to throw IllegalArgumentException if no target address can be determined. Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59124
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     1
/*
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     4
 *
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     8
 *
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    14
 *
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    18
 *
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    21
 * questions.
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    22
 */
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    23
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    24
/*
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    25
 * @test
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    26
 * @bug 8233141
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    27
 * @summary DatagramSocket.send should throw IllegalArgumentException
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    28
 *          when the packet address is not correctly set.
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    29
 * @run main AddressNotSet
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    30
 */
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    31
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    32
import java.net.DatagramPacket;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    33
import java.net.DatagramSocket;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    34
import java.net.InetAddress;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    35
import java.net.MulticastSocket;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    36
import java.net.SocketAddress;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    37
import java.nio.channels.DatagramChannel;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    38
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    39
import static java.lang.System.out;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    40
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    41
public class AddressNotSet {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    42
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    43
    final InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    44
    final DatagramSocket serversock;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    45
    int i;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    46
    AddressNotSet() throws Exception {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    47
        serversock = new DatagramSocket(0, loopbackAddress);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    48
    }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    49
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    50
    public static void main (String args[]) throws Exception {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    51
        new AddressNotSet().run();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    52
    }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    53
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    54
    public void run() throws Exception {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    55
        try (var ss = serversock) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    56
            try (DatagramSocket sock = new DatagramSocket()) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    57
                test(sock);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    58
            }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    59
            try (DatagramSocket sock = new MulticastSocket()) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    60
                test(sock);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    61
            }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    62
            try (DatagramSocket sock = DatagramChannel.open().socket()) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    63
                test(sock);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    64
            }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    65
        }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    66
    }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    67
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    68
    private void test(DatagramSocket sock) throws Exception {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    69
        out.println("Testing with " + sock.getClass());
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    70
        InetAddress addr = loopbackAddress;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    71
        byte[] buf;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    72
        DatagramPacket p;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    73
        int port = serversock.getLocalPort();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    74
        SocketAddress connectedAddress = serversock.getLocalSocketAddress();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    75
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    76
        out.println("Checking send to non-connected address ...");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    77
        try {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    78
            out.println("Checking send with no packet address");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    79
            buf = ("Hello, server"+(++i)).getBytes();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    80
            p = new DatagramPacket(buf, buf.length);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    81
            sock.send(p);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    82
            throw new AssertionError("Expected IllegalArgumentException not received");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    83
        } catch (IllegalArgumentException x) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    84
            out.println("Got expected exception: " + x);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    85
        }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    86
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    87
        out.println("Checking send to valid address");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    88
        buf = ("Hello, server"+(++i)).getBytes();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    89
        p = new DatagramPacket(buf, buf.length, addr, port);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    90
        sock.send(p);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    91
        serversock.receive(p);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    92
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    93
        out.println("Connecting to server address: " + connectedAddress);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    94
        sock.connect(connectedAddress);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    95
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    96
        try {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    97
            out.println("Checking send with different address than connected");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    98
            buf = ("Hello, server"+(++i)).getBytes();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
    99
            p = new DatagramPacket(buf, buf.length, addr, port+1);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   100
            sock.send(p);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   101
            throw new AssertionError("Expected IllegalArgumentException not received");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   102
        } catch (IllegalArgumentException x) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   103
            out.println("Got expected exception: " + x);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   104
        }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   105
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   106
        out.println("Checking send to valid address");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   107
        buf = ("Hello, server"+(++i)).getBytes();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   108
        p = new DatagramPacket(buf, buf.length, addr, port);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   109
        sock.send(p);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   110
        serversock.receive(p);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   111
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   112
        if (sock instanceof MulticastSocket) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   113
            sock.disconnect();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   114
            testTTL((MulticastSocket)sock);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   115
        }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   116
    }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   117
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   118
    private void testTTL(MulticastSocket sock) throws Exception {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   119
        out.println("Testing deprecated send TTL with " + sock.getClass());
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   120
        final byte ttl = 100;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   121
        InetAddress addr = loopbackAddress;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   122
        byte[] buf;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   123
        DatagramPacket p;
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   124
        int port = serversock.getLocalPort();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   125
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   126
        out.println("Checking send to non-connected address ...");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   127
        try {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   128
            out.println("Checking send with no packet address");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   129
            buf = ("Hello, server"+(++i)).getBytes();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   130
            p = new DatagramPacket(buf, buf.length);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   131
            sock.send(p,ttl);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   132
            throw new AssertionError("Expected IllegalArgumentException not received");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   133
        } catch (IllegalArgumentException x) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   134
            out.println("Got expected exception: " + x);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   135
        }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   136
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   137
        out.println("Connecting to connected address: " + sock);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   138
        sock.connect(addr, port);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   139
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   140
        try {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   141
            out.println("Checking send with different address than connected");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   142
            buf = ("Hello, server"+(++i)).getBytes();
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   143
            p = new DatagramPacket(buf, buf.length, addr, port+1);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   144
            sock.send(p, ttl);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   145
            throw new AssertionError("Expected IllegalArgumentException not received");
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   146
        } catch (IllegalArgumentException x) {
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   147
            out.println("Got expected exception: " + x);
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   148
        }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   149
    }
d01fe40e9cd8 8233141: DatagramSocket.send doesn't specify exception thrown when no target address
dfuchs
parents:
diff changeset
   150
}