Skip to content

Commit 79a6e1c

Browse files
committed
Recover from Harmony Type.toString() bug, which affects Android Froyo:
http://stackoverflow.com/a/8169250/28465
1 parent 141d694 commit 79a6e1c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

guava-testlib/src/com/google/common/testing/NullPointerTester.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,17 @@ private void testParameter(Object instance, Invokable<?, ?> invokable,
354354
}
355355
}
356356

357+
private static String bestAvailableString(
358+
TypeToken type, int position, Invokable<?, ?> invokable) {
359+
checkNotNull(type);
360+
try {
361+
return type.toString();
362+
} catch (NullPointerException androidBug6636) {
363+
// http://stackoverflow.com/a/8169250/28465
364+
return String.format("unknown (arg %s of %s)", position, invokable);
365+
}
366+
}
367+
357368
private Object[] buildParamList(Invokable<?, ?> invokable, int indexOfParamToSetToNull) {
358369
ImmutableList<Parameter> params = invokable.getParameters();
359370
Object[] args = new Object[params.size()];
@@ -364,7 +375,7 @@ private Object[] buildParamList(Invokable<?, ?> invokable, int indexOfParamToSet
364375
args[i] = getDefaultValue(param.getType());
365376
Assert.assertTrue(
366377
"Can't find or create a sample instance for type '"
367-
+ param.getType()
378+
+ bestAvailableString(param.getType(), i, invokable)
368379
+ "'; please provide one using NullPointerTester.setDefault()",
369380
args[i] != null || isNullable(param));
370381
}

0 commit comments

Comments
 (0)