Skip to content

Commit

Permalink
Assert in place of ArgumentError for null checks (flutter#5612)
Browse files Browse the repository at this point in the history
For consistency with the rest of dart:ui, check required parameters with
assert(param != null) rather than throwing ArgumentError. ArgumentError
is typically reserved for checking the validity of non-null args -- e.g.
that a list has the required number of elements.
  • Loading branch information
cbracken authored Jun 25, 2018
1 parent 2c158b6 commit 1340970
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
22 changes: 10 additions & 12 deletions lib/ui/isolate_name_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,29 @@ part of dart.ui;
abstract class IsolateNameServer {
// Looks up the [SendPort] associated with a given name. Returns null
// if the name does not exist.
//
// `name` must not be null.
static SendPort lookupPortByName(String name) {
if (name == null) {
throw new ArgumentError("'name' cannot be null.");
}
assert(name != null, "'name' cannot be null.");
return _lookupPortByName(name);
}

// Registers a SendPort with a given name. Returns true if registration is
// successful, false if the name entry already exists.
//
// `port` and `name` must not be null.
static bool registerPortWithName(SendPort port, String name) {
if (name == null) {
throw new ArgumentError("'name' cannot be null.");
}
if (port == null) {
throw new ArgumentError("'port' cannot be null.");
}
assert(port != null, "'port' cannot be null.");
assert(name != null, "'name' cannot be null.");
return _registerPortWithName(port, name);
}

// Removes a name to SendPort mapping given a name. Returns true if the
// mapping was successfully removed, false if the mapping does not exist.
//
// `name` must not be null.
static bool removePortNameMapping(String name) {
if (name == null) {
throw new ArgumentError("'name' cannot be null.");
}
assert(name != null, "'name' cannot be null.");
return _removePortNameMapping(name);
}

Expand Down
14 changes: 0 additions & 14 deletions testing/dart/isolate_name_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,6 @@ void main() {
receivePort2.close();
});

test('isolate name server null args', () {
// None of our IsolateNameServer methods should accept null.
expect(() => IsolateNameServer.lookupPortByName(null), throwsArgumentError);
expect(() => IsolateNameServer.registerPortWithName(null, 'abc'),
throwsArgumentError);
final receivePort = new ReceivePort();
final sendPort = receivePort.sendPort;
expect(() => IsolateNameServer.registerPortWithName(sendPort, null),
throwsArgumentError);
expect(() => IsolateNameServer.removePortNameMapping(null),
throwsArgumentError);
receivePort.close();
});

test('isolate name server multi-isolate', () async {
// Register our send port with the name server.
final receivePort = new ReceivePort();
Expand Down

0 comments on commit 1340970

Please sign in to comment.