From e78f8ca1c55628312772c9c110d12fca09126a7e Mon Sep 17 00:00:00 2001 From: Sergio Giro Date: Wed, 11 Mar 2015 12:32:30 +0000 Subject: java.lang.reflect: Use only relevant modifiers when converting to string Some modifiers not relevant might be used to encode internal information (eg bridge methods) that shouldn't be displayed when converting to string bug: 18488857 Change-Id: Ie82ed513b58083a795549a708197f1db52ffb796 --- libart/src/main/java/java/lang/reflect/Field.java | 11 +++++++---- libart/src/main/java/java/lang/reflect/Method.java | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'libart') diff --git a/libart/src/main/java/java/lang/reflect/Field.java b/libart/src/main/java/java/lang/reflect/Field.java index 11e8a6e..cad876b 100644 --- a/libart/src/main/java/java/lang/reflect/Field.java +++ b/libart/src/main/java/java/lang/reflect/Field.java @@ -182,10 +182,12 @@ public final class Field extends AccessibleObject implements Member { */ public String toGenericString() { StringBuilder sb = new StringBuilder(80); + // Limit modifier bits to the ones that toStringGeneric should return for fields. + + String modifiers = Modifier.getDeclarationFieldModifiers(getModifiers()); // append modifiers if any - int modifier = getModifiers(); - if (modifier != 0) { - sb.append(Modifier.toString(modifier)).append(' '); + if (!modifiers.isEmpty()) { + sb.append(modifiers).append(' '); } // append generic type Types.appendGenericType(sb, getGenericType()); @@ -861,7 +863,8 @@ public final class Field extends AccessibleObject implements Member { */ @Override public String toString() { - StringBuilder result = new StringBuilder(Modifier.toString(getModifiers())); + StringBuilder result = new StringBuilder( + Modifier.getDeclarationFieldModifiers(getModifiers())); if (result.length() != 0) { result.append(' '); } diff --git a/libart/src/main/java/java/lang/reflect/Method.java b/libart/src/main/java/java/lang/reflect/Method.java index 058fb96..f0e4f5c 100644 --- a/libart/src/main/java/java/lang/reflect/Method.java +++ b/libart/src/main/java/java/lang/reflect/Method.java @@ -398,7 +398,8 @@ public final class Method extends AbstractMethod implements GenericDeclaration, */ @Override public String toString() { - StringBuilder result = new StringBuilder(Modifier.toString(getModifiers())); + StringBuilder result = new StringBuilder( + Modifier.getDeclarationMethodModifiers(getModifiers())); if (result.length() != 0) { result.append(' '); -- cgit v1.1