Method Parameter Reflection spec

Alex Buckley alex.buckley at oracle.com
Thu Aug 22 12:11:52 PDT 2013


On 8/21/2013 8:04 AM, Eric McCorkle wrote:
> I will give Joe a day to add his comments.

You may have to ping Joe directly.

> Here's a list of all the ways MethodParameters attributes could go wrong:
>
> (i) Actual length does not match attribute_length
> (ii) The number of parameters (parameter_count) is wrong for the method
> (iii) A constant pool index is out of bounds.
> (iv) A constant pool index does not refer to a UTF-8 entry
> (v) A parameter's name is "", or contains an illegal character [0]
> (vi) The flags field contains an illegal flag (something other than
> FINAL, SYNTHETIC, or MANDATED)
>
> (i) causes a ClassFileFormatError when parsing the class file (as it
> should).  Right now, (iii) and (iv) cause an IllegalArgumentException to
> be thrown.

Does an inaccurate attribute_length item in a RuntimeVisibleAnnotations 
attribute cause a CFE from HotSpot when the class file is loaded? How 
about in an InnerClasses attribute? I am not at all sure that the Java 
Virtual Machine should ever throw a CFE for these attributes.

> I am working on a patch to correct the behavior for (ii)-(vi), so I can
> have Executable.getParameters() throw whatever exception you choose (ie.
> this is one of those rare moments of freedom).

I no longer think ReflectiveOperationException is appropriate to throw 
from anything parameter-related. I think the best option is a 
parameter-oriented version of AnnotationFormatError, but under 
RuntimeException rather than Error. AttributeFormatException maybe.

Sidebar: Why is AnnotationFormatError an Error? JLS 11 says an Error 
indicates an exception from which programs are not ordinarily expected 
to recover, but a reflective client can surely cope with a malformed 
annotation. I would agree AnnotationFormatError is kinda sorta a cousin 
of LinkageError, but in my view it should have been a RuntimeException.

> [0]: I seem to recall there being some discussion about backspaces, but
> the current version doesn't seem to rule them out.  Has this been changed?

I remember very little without a URL to a spec or mailing list thread :-)

Alex


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