test/jdk/java/nio/channels/DatagramChannel/SendToUnresolved.java
changeset 49316 73da889306b7
parent 49315 2d4964bc055d
parent 49313 49e0f711bb2b
child 49412 2c3b9dbba7bc
child 49495 f46bfa7a2956
child 56346 514c68575523
equal deleted inserted replaced
49315:2d4964bc055d 49316:73da889306b7
     1 /*
       
     2  * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /* @test
       
    25  * @bug 4675045
       
    26  * @summary Test DatagramChannel send to unresolved address
       
    27  * @library ..
       
    28  */
       
    29 
       
    30 import java.io.*;
       
    31 import java.net.*;
       
    32 import java.nio.*;
       
    33 import java.nio.channels.*;
       
    34 
       
    35 public class SendToUnresolved {
       
    36     public static void main(String [] argv) throws Exception {
       
    37         String host = TestUtil.UNRESOLVABLE_HOST;
       
    38         DatagramChannel dc = DatagramChannel.open();
       
    39         ByteBuffer bb = ByteBuffer.allocate(4);
       
    40         InetSocketAddress sa = new InetSocketAddress (host, 37);
       
    41         InetAddress inetaddr = sa.getAddress();
       
    42         try {
       
    43             dc.send(bb, sa);
       
    44             throw new RuntimeException("Expected exception not thrown");
       
    45         } catch (IOException | UnresolvedAddressException e) {
       
    46             // Correct result
       
    47         }
       
    48         dc.close();
       
    49     }
       
    50 }