From f7b710fcb3f2c62975a5e4a3053f1796efd1fb44 Mon Sep 17 00:00:00 2001 From: Aleksei Voitylov Date: Mon, 14 Mar 2022 14:33:28 +0300 Subject: [PATCH] 8277672: Better invocation handler handling Reviewed-by: yan Backport-of: 0691804665559f1935b7361d5f1207ac46f823f0 --- .../annotation/AnnotationInvocationHandler.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java b/jdk/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java index 515d649166..d8473c6855 100644 --- a/jdk/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java +++ b/jdk/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java @@ -457,8 +457,8 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable { if (!(memberType.isInstance(value) || value instanceof ExceptionProxy)) { value = new AnnotationTypeMismatchExceptionProxy( - value.getClass() + "[" + value + "]").setMember( - annotationType.members().get(name)); + objectToString(value)) + .setMember(annotationType.members().get(name)); } } mv.put(name, value); @@ -468,6 +468,15 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable { UnsafeAccessor.setMemberValues(this, mv); } + /* + * Create a textual representation of the argument without calling + * any overridable methods of the argument. + */ + private static String objectToString(Object value) { + return value.getClass().getName() + "@" + + Integer.toHexString(System.identityHashCode(value)); + } + private static class UnsafeAccessor { private static final sun.misc.Unsafe unsafe; private static final long typeOffset;