[Top][All Lists]

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

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

From: Steven Augart
Subject: Re: java.lang.Class.newinstance(): exceptions; desired behavior?
Date: Thu, 23 Sep 2004 15:39:26 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007

Archie Cobbs wrote:
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)
        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

Sun has yet to do anything about it.

IMHO in this case compatibility is best, however repulsive.

I have read the text of this, Archie, and I have to agree that we need to maintain compatibility (however repulsive) with the JDK. I'll prepare a separate doc fix patch to java.lang.Class so that this issue doesn't confuse others.

It is now the documented behaviour as of JDK 1.5.0rc1. (And it is *really annoying* to implement in a VM written in Java, like Jikes RVM).

Thanks for the quick reply, Archie.

--Steve Augart
Steven Augart

Jikes RVM, a free, open source, Virtual Machine:

reply via email to

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