Avoid returning null from a factory method
With Null Safety factory constructors will not be allowed to return `null`
values. We could make this into a static method, but it seems that there
already is an assertion that the argument is of a specific type, so I thought
that we could simply make it into a check and throw `ArgumentError` for
unsupported types.
Here's the global presubmit:
http://test/OCL:321566434:BASE:322085661:1595227618340:70519a7c
and its deflake:
http://test/OCL:321566434:BASE:322085661:1595232479037:1d5b2f0f
(tl;dr: it seems that there are only a few timeouts of flaky tests)
Do let me know if you prefer the alternative of using a static method instead.
PiperOrigin-RevId: 322342435
diff --git a/lib/support/firefox_profile.dart b/lib/support/firefox_profile.dart
index f10e626..68d0130 100644
--- a/lib/support/firefox_profile.dart
+++ b/lib/support/firefox_profile.dart
@@ -273,7 +273,6 @@
final T value;
factory PrefsOption(String name, T value) {
- assert(value is bool || value is int || value is String);
if (value is bool) {
return BooleanOption(name, value) as PrefsOption<T>;
} else if (value is int) {
@@ -281,7 +280,8 @@
} else if (value is String) {
return StringOption(name, value) as PrefsOption<T>;
}
- return null;
+ throw ArgumentError(
+ 'Only `bool`, `int` and `String` are valid parameter types.');
}
factory PrefsOption.parse(String prefs) {