changeset 2377:b1e8f41ed755

6639665: ThreadGroup finalizer allows creation of false root ThreadGroups Reviewed-by: alanb, hawtin
author chegar
date Mon, 23 Nov 2009 12:40:46 +0000
parents 08f57141c305
children e943f6b0b0e9
files src/share/classes/java/lang/ThreadGroup.java
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/ThreadGroup.java	Fri Nov 20 14:24:56 2009 -0800
+++ b/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.
      *