blob: 6f0b795a8944ec0efcced4fbb6938c32fe87af10 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
2 * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any 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
32import java.net.*;
33import java.io.IOException;
34
35public 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}