Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/ServerSocket/ThreadStop.java
38811 views
1
/*
2
* Copyright (c) 2002, 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(0);
43
}
44
45
public int localPort() {
46
return ss.getLocalPort();
47
}
48
49
50
public void run() {
51
try {
52
Socket s = ss.accept();
53
} catch (IOException ioe) {
54
} catch (ThreadDeath x) {
55
} finally {
56
try {
57
ss.close();
58
} catch (IOException x) { }
59
}
60
}
61
}
62
63
public static void main(String args[]) throws Exception {
64
65
// start a server
66
Server svr = new Server();
67
Thread thr = new Thread(svr);
68
thr.start();
69
70
// give server time to block in ServerSocket.accept()
71
Thread.currentThread().sleep(2000);
72
73
// "stop" the thread
74
thr.stop();
75
76
// give thread time to stop
77
Thread.currentThread().sleep(2000);
78
79
// it's platform specific if Thread.stop interrupts the
80
// thread - on Linux/Windows most likely that thread is
81
// still in accept() so we connect to server which causes
82
// it to unblock and do JNI-stuff with a pending exception
83
84
try {
85
Socket s = new Socket("localhost", svr.localPort());
86
} catch (IOException ioe) { }
87
88
}
89
90
}
91
92