Added more descriptive error to StandardMessageCodec for types that override toString() (flutter/engine#26527)
This commit is contained in:
@@ -288,7 +288,8 @@ public class StandardMessageCodec implements MessageCodec<Object> {
|
||||
writeFloat(stream, f);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported value: " + value);
|
||||
throw new IllegalArgumentException(
|
||||
"Unsupported value: '" + value + "' of type '" + value.getClass() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package io.flutter.plugin.common;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.text.SpannableString;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -122,4 +124,24 @@ public class StandardMessageCodecTest {
|
||||
String value = (String) codec.decodeMessage(message);
|
||||
assertEquals(value, "hello world");
|
||||
}
|
||||
|
||||
private static class NotEncodable {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "not encodable";
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorHasType() {
|
||||
StandardMessageCodec codec = new StandardMessageCodec();
|
||||
NotEncodable notEncodable = new NotEncodable();
|
||||
Exception exception =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> {
|
||||
codec.encodeMessage(notEncodable);
|
||||
});
|
||||
assertTrue(exception.getMessage().contains("NotEncodable"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user