Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/ServerSocket/ThreadStop.java
41149 views
1
/*
2
* Copyright (c) 2002, 2019, 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
/**
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 {
42
ss = new ServerSocket();
43
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
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()
72
Thread.sleep(2000);
73
74
// "stop" the thread
75
thr.stop();
76
77
// give thread time to stop
78
Thread.sleep(2000);
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
85
try (Socket s = new Socket(svr.ss.getInetAddress(), svr.localPort())) {
86
} catch (IOException ioe) {
87
}
88
thr.join();
89
}
90
91
}
92
93