Skip to content

Commit

Permalink
Workaround for Java bug that returns null in ParameterizedType.getAct…
Browse files Browse the repository at this point in the history
…ualTypeArguments() return array.
  • Loading branch information
Atsushi Eno committed Dec 5, 2012
1 parent fbc595d commit 0e670bb
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions JavaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ Type getGenericSuperclass (Class c)
return c.getInterfaces ();
}
}

static Type [] getActualTypeArguments (ParameterizedType ptype)
{
Type [] types = ptype.getActualTypeArguments ();
for (Type t : types)
if (t == null) // libcore failed to retrieve type.
return new Type [0];
return types;
}

int getConstructorParameterOffset (Constructor ctor)
{
Expand Down Expand Up @@ -766,16 +775,19 @@ else if (name.charAt (0) == 'L')
// toString() does not work fine for ParameterizedType, so do it by ourselves.
ParameterizedType ptype = (ParameterizedType) type;
StringBuilder sb = new StringBuilder ();
sb.append (getGenericTypeName (ptype.getRawType ())).append ('<');
boolean follow = false;
for (Type ta : ptype.getActualTypeArguments ()) {
if (follow)
sb.append (getGenericTypeName (ptype.getRawType ()));
boolean occured = false;
for (Type ta : getActualTypeArguments (ptype)) {
if (occured)
sb.append (", ");
else
follow = true;
else {
sb.append ('<');
occured = true;
}
sb.append (getGenericTypeName (ta));
}
sb.append ('>');
if (occured)
sb.append ('>');
return sb.toString ();
} else {
try {
Expand Down

0 comments on commit 0e670bb

Please sign in to comment.