6639665: ThreadGroup finalizer allows creation of false root ThreadGroups
authorchegar
Mon, 23 Nov 2009 12:40:46 +0000
changeset 5171 63fef5b098e9
parent 5170 17c2a503bf94
child 5172 3e3db347f963
6639665: ThreadGroup finalizer allows creation of false root ThreadGroups Reviewed-by: alanb, hawtin
jdk/src/share/classes/java/lang/ThreadGroup.java
--- a/jdk/src/share/classes/java/lang/ThreadGroup.java	Fri Nov 20 14:24:56 2009 -0800
+++ b/jdk/src/share/classes/java/lang/ThreadGroup.java	Mon Nov 23 12:40:46 2009 +0000
@@ -55,7 +55,7 @@
  */
 public
 class ThreadGroup implements Thread.UncaughtExceptionHandler {
-    ThreadGroup parent;
+    private final ThreadGroup parent;
     String name;
     int maxPriority;
     boolean destroyed;
@@ -76,6 +76,7 @@
     private ThreadGroup() {     // called from C code
         this.name = "system";
         this.maxPriority = Thread.MAX_PRIORITY;
+        this.parent = null;
     }
 
     /**
@@ -113,10 +114,10 @@
      * @since   JDK1.0
      */
     public ThreadGroup(ThreadGroup parent, String name) {
-        if (parent == null) {
-            throw new NullPointerException();
-        }
-        parent.checkAccess();
+        this(checkParentAccess(parent), parent, name);
+    }
+
+    private ThreadGroup(Void unused, ThreadGroup parent, String name) {
         this.name = name;
         this.maxPriority = parent.maxPriority;
         this.daemon = parent.daemon;
@@ -125,6 +126,16 @@
         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.
      *