1 /* 2 * Copyright (c) 2001, 2018, 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 8195160 26 * @summary Test various methods that should throw IAE when passed improper 27 * SocketAddress 28 * @requires (os.family == "linux") 29 * @library .. /test/lib 30 * @build RsocketTest 31 * @run main/othervm -Djava.net.preferIPv4Stack=true AddressTest 32 */ 33 34 import java.net.*; 35 import jdk.net.Sockets; 36 37 public class AddressTest { 38 class MySocketAddress extends SocketAddress { 39 public MySocketAddress() { 40 } 41 } 42 43 public AddressTest() throws Exception { 44 SocketAddress addr = new MySocketAddress(); 45 Socket soc = Sockets.openRdmaSocket(); 46 ServerSocket serv = Sockets.openRdmaServerSocket(); 47 boolean ok = false; 48 try { 49 soc.bind(addr); 50 } catch (IllegalArgumentException e) { 51 ok = true; 52 } catch (Exception e2) { 53 } 54 if (!ok) 55 throw new RuntimeException("Socket.bind should throw IllegalArgumentException!"); 56 57 ok = false; 58 soc.close(); 59 soc = Sockets.openRdmaSocket(); 60 try { 61 soc.connect(addr, 100); 62 } catch (IllegalArgumentException e) { 63 ok = true; 64 } catch (Exception e2) { 65 } 66 if (!ok) 67 throw new RuntimeException("Socket.connect should throw IllegalArgumentException!"); 68 69 ok = false; 70 try { 71 serv.bind(addr); 72 } catch (IllegalArgumentException e) { 73 ok = true; 74 } catch (Exception e2) { 75 } 76 if (!ok) 77 throw new RuntimeException("ServerSocket.bind should throw IllegalArgumentException!"); 78 } 79 80 public static void main(String[] args) throws Exception { 81 if (!RsocketTest.isRsocketAvailable()) 82 return; 83 84 new AddressTest(); 85 } 86 }