author | chegar |
Wed, 23 Nov 2011 12:30:19 +0000 | |
changeset 11038 | c5258e10c75b |
parent 5506 | 202f599c92aa |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
1148
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
1148
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
4 |
* |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
8 |
* |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
14 |
* |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
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. |
|
1148
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
22 |
*/ |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
23 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
24 |
/* |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
25 |
* @test |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
26 |
* @bug 6576763 |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
27 |
* @summary (thread) Thread constructors throw undocumented NPE for null name |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
28 |
*/ |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
29 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
30 |
/* |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
31 |
* Verify that threads constructed with a null thread name do not get added |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
32 |
* to the list of unstarted thread for a thread group. We can do this by |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
33 |
* checking that a daemon threadGroup is desroyed after its final valid thread |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
34 |
* has completed. |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
35 |
*/ |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
36 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
37 |
import java.util.concurrent.CountDownLatch; |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
38 |
import static java.lang.System.out; |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
39 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
40 |
public class NullThreadName |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
41 |
{ |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
42 |
static CountDownLatch done = new CountDownLatch(1); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
43 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
44 |
public static void main(String args[]) throws Exception { |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
45 |
ThreadGroup tg = new ThreadGroup("chegar-threads"); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
46 |
Thread goodThread = new Thread(tg, new GoodThread(), "goodThread"); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
47 |
try { |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
48 |
Thread badThread = new Thread(tg, new Runnable(){ |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
49 |
@Override |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
50 |
public void run() {} }, null); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
51 |
} catch (NullPointerException npe) { |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
52 |
out.println("OK, caught expected " + npe); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
53 |
} |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
54 |
tg.setDaemon(true); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
55 |
goodThread.start(); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
56 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
57 |
done.await(); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
58 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
59 |
int count = 0; |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
60 |
while (goodThread.isAlive()) { |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
61 |
/* Hold off a little to allow the thread to complete */ |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
62 |
out.println("GoodThread still alive, sleeping..."); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
63 |
try { Thread.sleep(2000); } |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
64 |
catch (InterruptedException unused) {} |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
65 |
|
11038
c5258e10c75b
6776144: java/lang/ThreadGroup/NullThreadName.java fails with Thread group is not destroyed ,fastdebug LINUX
chegar
parents:
5506
diff
changeset
|
66 |
/* do not wait forever - allow 120 seconds same as jtreg default timeout. */ |
c5258e10c75b
6776144: java/lang/ThreadGroup/NullThreadName.java fails with Thread group is not destroyed ,fastdebug LINUX
chegar
parents:
5506
diff
changeset
|
67 |
if (count++ > 60) |
1148
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
68 |
throw new AssertionError("GoodThread is still alive!"); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
69 |
} |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
70 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
71 |
if (!tg.isDestroyed()) { |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
72 |
throw new AssertionError("Failed: Thread group is not destroyed."); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
73 |
} |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
74 |
} |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
75 |
|
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
76 |
static class GoodThread implements Runnable |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
77 |
{ |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
78 |
@Override |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
79 |
public void run() { |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
80 |
out.println("Good Thread started..."); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
81 |
out.println("Good Thread finishing"); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
82 |
done.countDown(); |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
83 |
} |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
84 |
} |
1e917f49e503
6576763: Thread constructors throw undocumented NPE for null name
chegar
parents:
diff
changeset
|
85 |
} |