Skip to content
Permalink
Browse files
8266598: Exception values for AnnotationTypeMismatchException are not…
… always informative

Reviewed-by: jfranck
  • Loading branch information
raphw authored and Joel Borggrén-Franck committed Jun 9, 2021
1 parent 13d6180 commit 7b1e4024c02e6e831502e20cdbf54efb6240d12b
@@ -356,11 +356,18 @@ public static Object parseMemberValue(Class<?> memberType,

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 @@ private static Object parseEnumValue(Class<? extends Enum> enumType, ByteBuffer
String typeName = constPool.getUTF8At(typeNameIndex);
int constNameIndex = buf.getShort() & 0xFFFF;
String constName = constPool.getUTF8At(constNameIndex);
if (!enumType.isEnum()) {
return new AnnotationTypeMismatchExceptionProxy(
typeName + "." + constName);
} else if (enumType != parseSig(typeName, container)) {
if (!enumType.isEnum() || enumType != parseSig(typeName, container)) {
return new AnnotationTypeMismatchExceptionProxy(
typeName + "." + constName);
typeName.substring(1, typeName.length() - 1).replace('/', '.') + "." + constName);
}

try {
@@ -755,7 +759,7 @@ private static Object parseArrayElements(Object[] result,
*/
private static ExceptionProxy exceptionProxy(int tag) {
return new AnnotationTypeMismatchExceptionProxy(
"Array with component tag: " + tag);
"Array with component tag: " + (tag == 0 ? "0" : (char) tag));
}

/**
@@ -23,7 +23,7 @@

/*
* @test
* @bug 8228988
* @bug 8228988 8266598
* @summary An annotation-typed property of an annotation that is represented as an
* incompatible property of another type should yield an AnnotationTypeMismatchException.
* @modules java.base/jdk.internal.org.objectweb.asm
@@ -59,7 +59,11 @@ public static void main(String[] args) throws Exception {
Value value = sample.value();
throw new IllegalStateException("Found value: " + value);
} catch (AnnotationTypeMismatchException e) {
// correct
if (!e.element().getName().equals("value")) {
throw new IllegalStateException("Unexpected element: " + e.element());
} else if (!e.foundType().equals(AnEnum.class.getName() + "." + AnEnum.VALUE.name())) {
throw new IllegalStateException("Unexpected type: " + e.foundType());
}
}
}

@@ -23,7 +23,7 @@

/*
* @test
* @bug 8228988
* @bug 8228988 8266598
* @summary An enumeration-typed property of an annotation that is represented as an
* incompatible property of another type should yield an AnnotationTypeMismatchException.
* @modules java.base/jdk.internal.org.objectweb.asm
@@ -59,7 +59,11 @@ public static void main(String[] args) throws Exception {
AnEnum value = sample.value();
throw new IllegalStateException("Found value: " + value);
} catch (AnnotationTypeMismatchException e) {
// correct
if (!e.element().getName().equals("value")) {
throw new IllegalStateException("Unexpected element: " + e.element());
} else if (!e.foundType().equals("@" + AnAnnotation.class.getName() + "(" + AnEnum.VALUE.name() + ")")) {
throw new IllegalStateException("Unexpected type: " + e.foundType());
}
}
}

1 comment on commit 7b1e402

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 7b1e402 Jun 9, 2021

Please sign in to comment.