author | alanb |
Fri, 10 Sep 2010 18:48:49 +0100 | |
changeset 6538 | cb0da65ba680 |
parent 5798 | 9cc262cd2a7a |
child 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
1449
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
1449
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
4 |
* |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
8 |
* |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
13 |
* accompanied this code). |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
14 |
* |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
18 |
* |
5506 | 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. |
|
1449
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
22 |
*/ |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
23 |
|
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
24 |
/* @test |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
25 |
* @bug 5025260 |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
26 |
* @summary ClosedSelectorException is expected when register after close |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
27 |
*/ |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
28 |
|
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
29 |
import java.net.*; |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
30 |
import java.nio.channels.*; |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
31 |
|
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
32 |
public class CloseThenRegister { |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
33 |
|
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
34 |
public static void main (String [] args) throws Exception { |
5798
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
35 |
Selector sel = Selector.open(); |
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
36 |
sel.close(); |
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
37 |
ServerSocketChannel ssc = ServerSocketChannel.open(); |
1449
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
38 |
try { |
5798
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
39 |
ssc.bind(new InetSocketAddress(0)); |
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
40 |
ssc.configureBlocking(false); |
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
41 |
ssc.register(sel, SelectionKey.OP_ACCEPT); |
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
42 |
throw new RuntimeException("register after close does not cause CSE!"); |
1449
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
43 |
} catch (ClosedSelectorException cse) { |
5798
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
44 |
// expected |
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
45 |
} finally { |
9cc262cd2a7a
6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"
alanb
parents:
5506
diff
changeset
|
46 |
ssc.close(); |
1449
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
47 |
} |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
48 |
} |
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
49 |
|
2ed6188288d6
5025260: Register methods should throw ClosedChannelException instead of NPE
sherman
parents:
diff
changeset
|
50 |
} |