[cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

Andrew John Hughes gnu_andrew at member.fsf.org
Thu Apr 13 20:55:12 UTC 2006


On Wed, Apr 12, 2006 at 06:14:33PM +0200, Mark Wielaard wrote:
> 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  <mark at klomp.org>
> 
>     * 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)



The patch certainly seems to make the code cleaner, and match the documentation
better.  IMO, it should go in, but I didn't write the original code, only documented
it.  They may be a reason why Tom did it like this.

This code has been hanging around for about 18 months on the generics branch.
Seems like moving these things to HEAD is doing some good... :)

Cheers,
-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

If you use Microsoft Office, support movement towards the end of vendor lock-in:
http://opendocumentfellowship.org/petition/

"Value your freedom, or you will lose it, teaches history. 
`Don't bother us with politics' respond those who don't want to learn." 
-- Richard Stallman

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : http://developer.classpath.org/pipermail/classpath-patches/attachments/20060413/8995792e/attachment.pgp


More information about the Classpath-patches mailing list