提交 a21484e3 编写于 作者: C chegar

6639665: ThreadGroup finalizer allows creation of false root ThreadGroups

Reviewed-by: alanb, hawtin
上级 0dce40b2
...@@ -55,7 +55,7 @@ import sun.misc.VM; ...@@ -55,7 +55,7 @@ import sun.misc.VM;
*/ */
public public
class ThreadGroup implements Thread.UncaughtExceptionHandler { class ThreadGroup implements Thread.UncaughtExceptionHandler {
ThreadGroup parent; private final ThreadGroup parent;
String name; String name;
int maxPriority; int maxPriority;
boolean destroyed; boolean destroyed;
...@@ -76,6 +76,7 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler { ...@@ -76,6 +76,7 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler {
private ThreadGroup() { // called from C code private ThreadGroup() { // called from C code
this.name = "system"; this.name = "system";
this.maxPriority = Thread.MAX_PRIORITY; this.maxPriority = Thread.MAX_PRIORITY;
this.parent = null;
} }
/** /**
...@@ -113,10 +114,10 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler { ...@@ -113,10 +114,10 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @since JDK1.0 * @since JDK1.0
*/ */
public ThreadGroup(ThreadGroup parent, String name) { public ThreadGroup(ThreadGroup parent, String name) {
if (parent == null) { this(checkParentAccess(parent), parent, name);
throw new NullPointerException(); }
}
parent.checkAccess(); private ThreadGroup(Void unused, ThreadGroup parent, String name) {
this.name = name; this.name = name;
this.maxPriority = parent.maxPriority; this.maxPriority = parent.maxPriority;
this.daemon = parent.daemon; this.daemon = parent.daemon;
...@@ -125,6 +126,16 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler { ...@@ -125,6 +126,16 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler {
parent.add(this); parent.add(this);
} }
/*
* @throws NullPointerException if the parent argument is {@code null}
* @throws SecurityException if the current thread cannot create a
* thread in the specified thread group.
*/
private static Void checkParentAccess(ThreadGroup parent) {
parent.checkAccess();
return null;
}
/** /**
* Returns the name of this thread group. * Returns the name of this thread group.
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册