classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: java.lang.Class.newinstance(): exceptions; desired behavior?


From: Archie Cobbs
Subject: Re: java.lang.Class.newinstance(): exceptions; desired behavior?
Date: Thu, 23 Sep 2004 12:41:04 -0500 (CDT)

Steven Augart wrote:
> I think our implementation of java.lang.Class's newinstance() is
> incorrect.  Specifically, Class.newinstance() uses reflection to
> invoke a class's zero-argument constructor and then, if it catches an
> InvocationTargetException, unwraps that exception, throwing whatever
> exception was originally thrown by the constructor.
> 
> The exact code we currently have is:
> 
>     catch (InvocationTargetException e)
>       {
>       VMClass.throwException(e.getTargetException());
>       throw (InternalError) new InternalError
>         ("VMClass.throwException returned").initCause(e);
>       }
> 
> This has the effect that Class.newinstance() can throw any exception
> at all, without any warning to the caller.  

This is a well-known bug in the spec.. see

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4233093

Sun has yet to do anything about it.

IMHO in this case compatibility is best, however repulsive.

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]