8266598: Exception values for AnnotationTypeMismatchException are not always informative

Reviewed-by: jfranck
This commit is contained in:
Rafael Winterhalter 2021-06-09 13:21:32 +00:00 committed by Joel Borggrén-Franck
parent 13d6180421
commit 7b1e4024c0
3 changed files with 25 additions and 13 deletions

View file

@ -356,11 +356,18 @@ public class AnnotationParser {
if (result == null) {
result = new AnnotationTypeMismatchExceptionProxy(
memberType.getClass().getName());
Proxy.isProxyClass(memberType)
? memberType.getInterfaces()[0].getName()
: memberType.getName());
} else if (!(result instanceof ExceptionProxy) &&
!memberType.isInstance(result)) {
result = new AnnotationTypeMismatchExceptionProxy(
result.getClass() + "[" + result + "]");
if (result instanceof Annotation) {
result = new AnnotationTypeMismatchExceptionProxy(
result.toString());
} else {
result = new AnnotationTypeMismatchExceptionProxy(
result.getClass().getName() + "[" + result + "]");
}
}
return result;
}
@ -463,12 +470,9 @@ public class AnnotationParser {
String typeName = constPool.getUTF8At(typeNameIndex);
int constNameIndex = buf.getShort() & 0xFFFF;
String constName = constPool.getUTF8At(constNameIndex);
if (!enumType.isEnum()) {
if (!enumType.isEnum() || enumType != parseSig(typeName, container)) {
return new AnnotationTypeMismatchExceptionProxy(
typeName + "." + constName);
} else if (enumType != parseSig(typeName, container)) {
return new AnnotationTypeMismatchExceptionProxy(
typeName + "." + constName);
typeName.substring(1, typeName.length() - 1).replace('/', '.') + "." + constName);
}
try {
@ -755,7 +759,7 @@ public class AnnotationParser {
*/
private static ExceptionProxy exceptionProxy(int tag) {
return new AnnotationTypeMismatchExceptionProxy(
"Array with component tag: " + tag);
"Array with component tag: " + (tag == 0 ? "0" : (char) tag));
}
/**