@@ -52,11 +52,29 @@ public class ReflectHelpers {
5252
5353 private static final Joiner COMMA_SEPARATOR = Joiner .on (", " );
5454
55+ /**
56+ * Returns the simple name of the given class, or a fallback simple name derived from the class
57+ * name if {@link Class#getSimpleName()} throws an exception (such as an {@link
58+ * IllegalAccessError} on Java 17+ for non-public inner classes).
59+ */
60+ public static String getSimpleName (Class <?> clazz ) {
61+ try {
62+ return clazz .getSimpleName ();
63+ } catch (Throwable t ) {
64+ if (clazz .isArray ()) {
65+ return getSimpleName (clazz .getComponentType ()) + "[]" ;
66+ }
67+ String name = clazz .getName ();
68+ int idx = Math .max (name .lastIndexOf ('.' ), name .lastIndexOf ('$' ));
69+ return idx != -1 ? name .substring (idx + 1 ) : name ;
70+ }
71+ }
72+
5573 /** Returns a string representation of the signature of a {@link Method}. */
5674 public static String formatMethod (Method input ) {
5775 String parameterTypes =
5876 FluentIterable .from (asList (input .getParameterTypes ()))
59- .transform (Class ::getSimpleName )
77+ .transform (ReflectHelpers ::getSimpleName )
6078 .join (COMMA_SEPARATOR );
6179 return String .format ("%s(%s)" , input .getName (), parameterTypes );
6280 }
@@ -100,7 +118,7 @@ private static void format(StringBuilder builder, Type t) {
100118 }
101119
102120 private static void formatClass (StringBuilder builder , Class <?> clazz ) {
103- builder .append (clazz . getSimpleName ());
121+ builder .append (getSimpleName (clazz ));
104122 }
105123
106124 private static void formatTypeVariable (StringBuilder builder , TypeVariable <?> t ) {
0 commit comments