From 0b939b3cf1eefe461f06ce6a42dfa4028f657cba Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 25 Jun 2018 16:33:33 -0700 Subject: [PATCH] Assert in place of ArgumentError for null checks (flutter/engine#5612) 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. --- .../flutter/lib/ui/isolate_name_server.dart | 22 +++++++++---------- .../dart/isolate_name_server_test.dart | 14 ------------ 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/engine/src/flutter/lib/ui/isolate_name_server.dart b/engine/src/flutter/lib/ui/isolate_name_server.dart index 8dcbf79977..0e33f4e079 100644 --- a/engine/src/flutter/lib/ui/isolate_name_server.dart +++ b/engine/src/flutter/lib/ui/isolate_name_server.dart @@ -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); } diff --git a/engine/src/flutter/testing/dart/isolate_name_server_test.dart b/engine/src/flutter/testing/dart/isolate_name_server_test.dart index 4df83cf771..b8e4a342ec 100644 --- a/engine/src/flutter/testing/dart/isolate_name_server_test.dart +++ b/engine/src/flutter/testing/dart/isolate_name_server_test.dart @@ -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();