[Top][All Lists]

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

Re: java.lang.Constructor conformance

From: Tom Tromey
Subject: Re: java.lang.Constructor conformance
Date: 08 Aug 2001 12:20:31 -0600

>>>>> "Patrick" == Patrick Doyle <address@hidden> writes:

Patrick> When a constructor isn't found, Classpath's
Patrick> java.lang.Constructor dutifully throws
Patrick> InstantiationException, as per Sun's library spec.  However,
Patrick> the JDK itself actually throws NoSuchMethodError (not to be
Patrick> confused with NoSuchMethodException).  Kaffe also throws
Patrick> NoSuchMethodError.


What version of the JDK are you using?
JDK 1.2 throws InstantiationException.

Patrick> Technically, Classpath is right, but I'm not sure whether
Patrick> that's more important than matching the behaviour of Sun's
Patrick> JVM.

Tough call.

Patrick> The way to fix it is to catch the NoSuchMethodException from
Patrick> Constructor.newInstance, and (believe it or not) re-throw it as a
Patrick> NoSuchMethodError.  Then Classpath should act just like the JDK.

libgcj throws NoSuchMethodException.  I know we didn't just make this
up, so I tracked it down.  The JCL book says that Class.newInstance
throws NoSuchMethodException if the class does not have a no-arg

Oh, well -- another case where Sun's documentation and implementation
are inconsistent and vary randomly across versions.  Yay.  The upshot
is that Java programs can't rely on the behavior.


reply via email to

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