Hi Archie,

On Wed, 2006-04-12 at 09:10 -0500, Archie Cobbs wrote:
> Mark Wielaard wrote:
> > +  /** 
> > +   * <p>
> > +   * Returns the handler used when this thread terminates due to an
> > +   * uncaught exception.  The handler used is determined by the following:
> > +   * </p>
> > +   * <ul>
> > +   * <li>If this thread has its own handler, this is returned.</li>
> > +   * <li>If not, then the handler of the thread's <code>ThreadGroup</code>
> > +   * object is returned.</li>
> > +   * <li>If both are unavailable, then <code>null</code> is returned.</li>
> > +   * </ul>
> > +   * 
> > +   * @return the appropriate <code>UncaughtExceptionHandler</code> or
> > +   *         <code>null</code> if one can't be obtained.
> > +   * @since 1.5 
> > +   */
> > +  public UncaughtExceptionHandler getUncaughtExceptionHandler()
> > +  {
> > +    return exceptionHandler;
> > +  }
> 
> The Javadoc and the implementation here don't seem consistent: how
> could this ever return the thread's ThreadGroup (option #2)?

Good catch. The documentation describes how VMThread handles this. But
it looks like we can simplify that code by just doing it here as the
documentation says.

Andrew/Tom, you wrote/documented that code what do you think of this
patch?

2006-04-12  Mark Wielaard  <[EMAIL PROTECTED]>

    * java/lang/Thread.java (getUncaughtExceptionHandler): Return
    thread group when exceptionHandler isn't set.
    * vm/reference/java/lang/VMThread.java (run): Use result of
    thread.getUncaughtExceptionHandler directly.

Cheers,

Mark
Index: java/lang/Thread.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
retrieving revision 1.19
diff -u -r1.19 Thread.java
--- java/lang/Thread.java	12 Apr 2006 12:04:18 -0000	1.19
+++ java/lang/Thread.java	12 Apr 2006 16:08:50 -0000
@@ -1051,7 +1051,9 @@
    * <li>If this thread has its own handler, this is returned.</li>
    * <li>If not, then the handler of the thread's <code>ThreadGroup</code>
    * object is returned.</li>
-   * <li>If both are unavailable, then <code>null</code> is returned.</li>
+   * <li>If both are unavailable, then <code>null</code> is returned
+   *     (which can only happen when the thread was terminated since
+   *      then it won't have an associated thread group anymore).</li>
    * </ul>
    * 
    * @return the appropriate <code>UncaughtExceptionHandler</code> or
@@ -1060,7 +1062,7 @@
    */
   public UncaughtExceptionHandler getUncaughtExceptionHandler()
   {
-    return exceptionHandler;
+    return exceptionHandler != null : exceptionHandler ? group;
   }
 
   /** 
Index: vm/reference/java/lang/VMThread.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMThread.java,v
retrieving revision 1.10
diff -u -r1.10 VMThread.java
--- vm/reference/java/lang/VMThread.java	12 Apr 2006 12:04:18 -0000	1.10
+++ vm/reference/java/lang/VMThread.java	12 Apr 2006 16:08:50 -0000
@@ -1,5 +1,5 @@
 /* VMThread -- VM interface for Thread of executable code
-   Copyright (C) 2003, 2004, 2005 Free Software Foundation
+   Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -123,9 +123,8 @@
 	    {
 		try
 		{
-		  Thread.UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
-		  if (handler == null)
-		    handler = thread.group;
+		  Thread.UncaughtExceptionHandler handler;
+		  handler = thread.getUncaughtExceptionHandler();
 		  handler.uncaughtException(thread, t);
 		}
 		catch(Throwable ignore)

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to