The specifications for java.lang.reflect's Method.invoke() and
Constructor.newInstance() APIs are effectively descriptions of the
implementation in the Classic VM. In particular, they specify an order
of operation of certain necessary run-time checks to ensure that the
invocation or instantiation may proceed. It certain implementations of
these APIs it is more efficient to reorder some of these run-time
checks, which can result in a different exception being thrown than in
the Classic VM implementation if more than one of the run-time checks
would fail. (See bug 4457255.)
From a discussion with Joshua.Bloch@eng, the preferred API style in
the Java libraries at large is to leave unspecified which exception
will be thrown if the conditions allow more than one to be thrown. We
propose to respecify Method.invoke() and Constructor.newInstance() to
follow this style.
New javadocs for Method.invoke():
/**
* Invokes the underlying method represented by this <code>Method</code>
* object, on the specified object with the specified parameters.
* Individual parameters are automatically unwrapped to match
* primitive formal parameters, and both primitive and reference
* parameters are subject to method invocation conversions as
* necessary.
*
* <p>If the underlying method is static, then the specified <code>obj</code>
* argument is ignored. It may be null.
*
* <p>If the number of formal parameters required by the underlying method is
* 0, the supplied <code>args</code> array may be of length 0 or null.
*
* <p>If the underlying method is an instance method, it is invoked
* using dynamic method lookup as documented in The Java Language
* Specification, section 15.12.4.4; in particular, overriding
* based on the runtime type of the target object will occur.
*
* <p>If the required access and argument checks succeed and the
* instantiation will proceed, if the underlying method is static,
* the class that declared the method is initialized if it has not
* already been initialized.
*
* <p>If the method completes normally, the value it returns is
* returned to the caller of invoke; if the value has a primitive
* type, it is first appropriately wrapped in an object. If the
* underlying method return type is void, the invocation returns
* null.
*
* @exception IllegalAccessException if this <code>Method</code> object
* enforces Java language access control and the underlying
* method is inaccessible.
* @exception IllegalArgumentException if the method is an
* instance method and the specified object argument
* is not an instance of the class or interface
* declaring the underlying method (or of a subclass
* or implementor thereof); if the number of actual
* and formal parameters differ; if an unwrapping
* conversion for primitive arguments fails; or if,
* after possible unwrapping, a parameter value
* cannot be converted to the corresponding formal
* parameter type by a method invocation conversion.
* @exception InvocationTargetException if the underlying method
* throws an exception.
* @exception NullPointerException if the specified object is null
* and the method is an instance method.
* @exception ExceptionInInitializerError if the initialization
* provoked by this method fails.
*/
New javadocs for Constructor.newInstance():
/**
* Uses the constructor represented by this <code>Constructor</code> object to
* create and initialize a new instance of the constructor's
* declaring class, with the specified initialization parameters.
* Individual parameters are automatically unwrapped to match
* primitive formal parameters, and both primitive and reference
* parameters are subject to method invocation conversions as necessary.
*
* <p>If the number of formal parameters required by the underlying constructor
* is 0, the supplied <code>initargs</code> array may be of length 0 or null.
*
* <p>If the required access and argument checks succeed and the
* instantiation will proceed, the constructor's declaring class
* is initialized if it has not already been initialized.
*
* <p>If the constructor completes normally, returns the newly
* created and initialized instance.
*
* @exception IllegalAccessException if this <code>Constructor</code> object
* enforces Java language access control and the underlying
* constructor is inaccessible.
* @exception IllegalArgumentException if the number of actual
* and formal parameters differ; if an unwrapping
* conversion for primitive arguments fails; or if,
* after possible unwrapping, a parameter value
* cannot be converted to the corresponding formal
* parameter type by a method invocation conversion.
* @exception InstantiationException if the class that declares the
* underlying constructor represents an abstract class.
* @exception InvocationTargetException if the underlying constructor
* throws an exception.
* @exception ExceptionInInitializerError if the initialization provoked
* by this method fails.
*/
Constructor.newInstance() APIs are effectively descriptions of the
implementation in the Classic VM. In particular, they specify an order
of operation of certain necessary run-time checks to ensure that the
invocation or instantiation may proceed. It certain implementations of
these APIs it is more efficient to reorder some of these run-time
checks, which can result in a different exception being thrown than in
the Classic VM implementation if more than one of the run-time checks
would fail. (See bug 4457255.)
From a discussion with Joshua.Bloch@eng, the preferred API style in
the Java libraries at large is to leave unspecified which exception
will be thrown if the conditions allow more than one to be thrown. We
propose to respecify Method.invoke() and Constructor.newInstance() to
follow this style.
New javadocs for Method.invoke():
/**
* Invokes the underlying method represented by this <code>Method</code>
* object, on the specified object with the specified parameters.
* Individual parameters are automatically unwrapped to match
* primitive formal parameters, and both primitive and reference
* parameters are subject to method invocation conversions as
* necessary.
*
* <p>If the underlying method is static, then the specified <code>obj</code>
* argument is ignored. It may be null.
*
* <p>If the number of formal parameters required by the underlying method is
* 0, the supplied <code>args</code> array may be of length 0 or null.
*
* <p>If the underlying method is an instance method, it is invoked
* using dynamic method lookup as documented in The Java Language
* Specification, section 15.12.4.4; in particular, overriding
* based on the runtime type of the target object will occur.
*
* <p>If the required access and argument checks succeed and the
* instantiation will proceed, if the underlying method is static,
* the class that declared the method is initialized if it has not
* already been initialized.
*
* <p>If the method completes normally, the value it returns is
* returned to the caller of invoke; if the value has a primitive
* type, it is first appropriately wrapped in an object. If the
* underlying method return type is void, the invocation returns
* null.
*
* @exception IllegalAccessException if this <code>Method</code> object
* enforces Java language access control and the underlying
* method is inaccessible.
* @exception IllegalArgumentException if the method is an
* instance method and the specified object argument
* is not an instance of the class or interface
* declaring the underlying method (or of a subclass
* or implementor thereof); if the number of actual
* and formal parameters differ; if an unwrapping
* conversion for primitive arguments fails; or if,
* after possible unwrapping, a parameter value
* cannot be converted to the corresponding formal
* parameter type by a method invocation conversion.
* @exception InvocationTargetException if the underlying method
* throws an exception.
* @exception NullPointerException if the specified object is null
* and the method is an instance method.
* @exception ExceptionInInitializerError if the initialization
* provoked by this method fails.
*/
New javadocs for Constructor.newInstance():
/**
* Uses the constructor represented by this <code>Constructor</code> object to
* create and initialize a new instance of the constructor's
* declaring class, with the specified initialization parameters.
* Individual parameters are automatically unwrapped to match
* primitive formal parameters, and both primitive and reference
* parameters are subject to method invocation conversions as necessary.
*
* <p>If the number of formal parameters required by the underlying constructor
* is 0, the supplied <code>initargs</code> array may be of length 0 or null.
*
* <p>If the required access and argument checks succeed and the
* instantiation will proceed, the constructor's declaring class
* is initialized if it has not already been initialized.
*
* <p>If the constructor completes normally, returns the newly
* created and initialized instance.
*
* @exception IllegalAccessException if this <code>Constructor</code> object
* enforces Java language access control and the underlying
* constructor is inaccessible.
* @exception IllegalArgumentException if the number of actual
* and formal parameters differ; if an unwrapping
* conversion for primitive arguments fails; or if,
* after possible unwrapping, a parameter value
* cannot be converted to the corresponding formal
* parameter type by a method invocation conversion.
* @exception InstantiationException if the class that declares the
* underlying constructor represents an abstract class.
* @exception InvocationTargetException if the underlying constructor
* throws an exception.
* @exception ExceptionInInitializerError if the initialization provoked
* by this method fails.
*/
- relates to
-
JDK-4457255 modena c0863105 test fails (wrong exception?) with compiler1.
-
- Closed
-