United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6798955 : Make MirroredTypesException be the parent class of MirroredTypeException

Details
Type:
Bug
Submit Date:
2009-01-29
Status:
Closed
Updated Date:
2010-06-07
Project Name:
JDK
Resolved Date:
2010-06-07
Component:
core-libs
OS:
generic
Sub-Component:
javax.lang.model
CPU:
generic
Priority:
P3
Resolution:
Duplicate
Affected Versions:
7
Fixed Versions:
7

Related Reports
Duplicate:
Relates:
Relates:

Sub Tasks

Description
To allow fewer catch blocks to do more, it would help if MirroredTypesException and MirroredTypeException to have superclass-subclass relationship rather than just both being runtime exceptions.  MirroredTypeException should be the specialized type since it fundamentally just should return a list of length one.

                                    

Comments
EVALUATION

Subclassing of MirroredType[s]Exception changed as part of fix for 6519115.
                                     
2010-06-07
EVALUATION

API usability issue should be addressed.
                                     
2009-01-29
PUBLIC COMMENTS

Seems harmless but also pointless. Typical processor code would be catching either one or the other exception type at a time:

SomeAnno ann = element.getAnnotation(SomeAnno.class);
try {
  ann.someMethodReturningClass();
} catch (MirroredTypeException x) {
  TypeMirror theReturnValue = x.getTypeMirror();
  // ...
}
try {
  ann.someMethodReturningClassArray();
} catch (MirroredTypesException x) {
  List<? extends TypeMirror> theReturnValue = x.getTypeMirrors();
  // ...
}

For it to be useful for a catch block of MirroredTypesException to also get MirroredTypeException with a singleton list, the calling code would have to have no idea whether the method it was calling returned Class or Class[]. But that would only happen if the calling code were operating reflectively on an annotation type not known to it statically - in which case Element.getAnnotation(Class) is useless, since you would more easily work with Element.getAnnotationMirrors().

As the Javadoc for getAnnotation says, "this method is intended for callers that are written to operate on a known, fixed set of annotation types", exactly the callers that will be catching either MirroredTypeException or MirroredTypesException when calling known, fixed methods.
                                     
2009-01-29



Hardware and Software, Engineered to Work Together