author | phedlin |
Fri, 15 Nov 2019 16:39:08 +0100 | |
changeset 59291 | 54cf02d52c1b |
parent 55045 | 3a8433d967ea |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55045
3a8433d967ea
8224035: Replace wildcard address with loopback or local host in tests - part 9
aefimov
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 4680160 |
|
27 |
* @summary The deprecated Thread.stop exposes un-checked JNI calls |
|
28 |
* that result in crashes when NULL is passed into subsequent |
|
29 |
* JNI calls. |
|
30 |
*/ |
|
31 |
||
32 |
import java.net.*; |
|
33 |
import java.io.IOException; |
|
34 |
||
35 |
public class ThreadStop { |
|
36 |
||
37 |
static class Server implements Runnable { |
|
38 |
||
39 |
ServerSocket ss; |
|
40 |
||
41 |
Server() throws IOException { |
|
55045
3a8433d967ea
8224035: Replace wildcard address with loopback or local host in tests - part 9
aefimov
parents:
47216
diff
changeset
|
42 |
ss = new ServerSocket(); |
3a8433d967ea
8224035: Replace wildcard address with loopback or local host in tests - part 9
aefimov
parents:
47216
diff
changeset
|
43 |
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); |
2 | 44 |
} |
45 |
||
46 |
public int localPort() { |
|
47 |
return ss.getLocalPort(); |
|
48 |
} |
|
49 |
||
50 |
||
51 |
public void run() { |
|
52 |
try { |
|
53 |
Socket s = ss.accept(); |
|
54 |
} catch (IOException ioe) { |
|
55 |
} catch (ThreadDeath x) { |
|
56 |
} finally { |
|
57 |
try { |
|
58 |
ss.close(); |
|
59 |
} catch (IOException x) { } |
|
60 |
} |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
public static void main(String args[]) throws Exception { |
|
65 |
||
66 |
// start a server |
|
67 |
Server svr = new Server(); |
|
68 |
Thread thr = new Thread(svr); |
|
69 |
thr.start(); |
|
70 |
||
71 |
// give server time to block in ServerSocket.accept() |
|
41136
44ba1622deee
8154525: java/net/ServerSocket/ThreadStop.java fails intermittently with error while cleaning up threads after test
xiaofeya
parents:
5506
diff
changeset
|
72 |
Thread.sleep(2000); |
2 | 73 |
|
74 |
// "stop" the thread |
|
75 |
thr.stop(); |
|
76 |
||
77 |
// give thread time to stop |
|
41136
44ba1622deee
8154525: java/net/ServerSocket/ThreadStop.java fails intermittently with error while cleaning up threads after test
xiaofeya
parents:
5506
diff
changeset
|
78 |
Thread.sleep(2000); |
2 | 79 |
|
80 |
// it's platform specific if Thread.stop interrupts the |
|
81 |
// thread - on Linux/Windows most likely that thread is |
|
82 |
// still in accept() so we connect to server which causes |
|
83 |
// it to unblock and do JNI-stuff with a pending exception |
|
84 |
||
55045
3a8433d967ea
8224035: Replace wildcard address with loopback or local host in tests - part 9
aefimov
parents:
47216
diff
changeset
|
85 |
try (Socket s = new Socket(svr.ss.getInetAddress(), svr.localPort())) { |
41136
44ba1622deee
8154525: java/net/ServerSocket/ThreadStop.java fails intermittently with error while cleaning up threads after test
xiaofeya
parents:
5506
diff
changeset
|
86 |
} catch (IOException ioe) { |
44ba1622deee
8154525: java/net/ServerSocket/ThreadStop.java fails intermittently with error while cleaning up threads after test
xiaofeya
parents:
5506
diff
changeset
|
87 |
} |
44ba1622deee
8154525: java/net/ServerSocket/ThreadStop.java fails intermittently with error while cleaning up threads after test
xiaofeya
parents:
5506
diff
changeset
|
88 |
thr.join(); |
2 | 89 |
} |
90 |
||
91 |
} |