Method Parameter Reflection spec

Eric McCorkle eric.mccorkle at oracle.com
Mon Aug 19 14:57:00 PDT 2013


The current version of the spec indicates that methods in
java.lang.reflect.Parameter should throw ReflectiveOperationException
for several cases (wrong number of parameters, bad parameter name, bad
constant pool index).

I'd like to suggest two (separate) minor revisions:

1) Executable.getParameters() should throw the
ReflectiveOperationException in the case of an invalid name or the wrong
number of parameters.  The rationale is as follows:

 * Doing it this way makes it straightforward to implement
j.l.r.Parameter as an immutable object.  Having methods in Parameter
throw the exception means Parameter objects will have to remember
whether or not they have verified their name (or else verify the name
every time they are called).

 * Having every single method in Parameter possibly check whether the
number of parameters that were returned from the VM is correct seems
rather awkward, as opposed to having a single check when Executable
obtains the Parameter array back from the VM.

2) In the event of a bad constant pool index, an IllegalArgumentException.

 * The current behavior of hotspot whenever it expects a UTF-8 constant
pool entry, but sees either an out-of-bounds index or something other
than a UTF-8 is to throw an IllegalArgumentException.


More information about the enhanced-metadata-spec-discuss mailing list