Hello,

Some background, when everything is going well, the toString form of an annotation looks something like

// Old non-erroneous annotation

@DangerousAnnotation(utopia=BRIGADOON,
thirtyTwoBitsAreNotEnough=42,
classy=interface Fleeting,
classies=[class java.lang.Object, int],
moreClassies=[])

with newlines added for clarity. However, there are various kinds of problems that can occur with the data in an annotation and in those cases an exception proxy is created so that if the corresponding method is called an exception is thrown rather than the data being returned. In these cases the string form of an annotation with exceptions-that-would-be-thrown-if-methods-are-called looks like:

// Current erroneous annotation

@DangerousAnnotation(utopia=sun.reflect.annotation.EnumConstantNotPresentExceptionProxy@766a8c91,
thirtyTwoBitsAreNotEnough=sun.reflect.annotation.AnnotationTypeMismatchExceptionProxy@1f40866a,
classy=sun.reflect.annotation.TypeNotPresentExceptionProxy@3de4f72b,
classies=[class java.lang.Object, int],
moreClassies=[])

Having the proxy implementation leak through to the string representation in this case is not helpful and the string can be made more informative. In addition, for Class-related values, the current form doesn't use the syntax which is legal in source code for annotations. Class-valued annotations are set using Class literal syntax, "Foo.class" rather than "class Foo", and arrays of Class-valued item should use braces ("{}") rather than brackets, ("[]").

For example, it would be better to have annotation string representations which looked like:

// New non-erroneous annotation

@DangerousAnnotation(utopia=BRIGADOON,
thirtyTwoBitsAreNotEnough=42,
classy=Fleeting.class,
classies={java.lang.Object.class, int.class},
moreClassies={})

// New erroneous annotation

@DangerousAnnotation(utopia=BRIGADOON /* Warning: constant not present! */,
thirtyTwoBitsAreNotEnough=/* Warning type mismatch! "class java.lang.Integer[42]" */,
classy=Fleeting.class /* Warning: type not present! */,
classies={java.lang.Object.class, int.class},
moreClassies={})

Please review the code to implement these behavioral changes:

5040830: (ann) please improve toString() for annotations containing exception proxies
    http://cr.openjdk.java.net/~darcy/5040830.2

(If you have erroneous Class-value items in an array of Class values, then this throws an exception since the exception proxy cannot be stored into the Class[].)

Thanks,

-Joe

Reply via email to