Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab3c822

Browse files
authored
Remove unnecessary null checks in dev/devicelab (#118842)
1 parent f291eb3 commit ab3c822

File tree

9 files changed

+12
-74
lines changed

9 files changed

+12
-74
lines changed

dev/devicelab/bin/tasks/module_custom_host_app_name_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Future<void> main() async {
275275

276276
String modes = readonlyDebugAssetFile.statSync().modeString();
277277
print('\nread-only.txt file access modes = $modes');
278-
if (modes != null && modes.compareTo(fileReadWriteMode) != 0) {
278+
if (modes.compareTo(fileReadWriteMode) != 0) {
279279
return TaskResult.failure('Failed to make assets user-readable and writable');
280280
}
281281

@@ -347,7 +347,7 @@ Future<void> main() async {
347347

348348
modes = readonlyReleaseAssetFile.statSync().modeString();
349349
print('\nread-only.txt file access modes = $modes');
350-
if (modes != null && modes.compareTo(fileReadWriteMode) != 0) {
350+
if (modes.compareTo(fileReadWriteMode) != 0) {
351351
return TaskResult.failure('Failed to make assets user-readable and writable');
352352
}
353353

dev/devicelab/bin/tasks/module_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Future<void> main() async {
278278

279279
String modes = readonlyDebugAssetFile.statSync().modeString();
280280
print('\nread-only.txt file access modes = $modes');
281-
if (modes != null && modes.compareTo(fileReadWriteMode) != 0) {
281+
if (modes.compareTo(fileReadWriteMode) != 0) {
282282
return TaskResult.failure('Failed to make assets user-readable and writable');
283283
}
284284

@@ -326,7 +326,7 @@ Future<void> main() async {
326326
// Shouldn't be missing since we already checked it exists above.
327327
final ArchiveFile? noticesFile = apk.findFile('assets/flutter_assets/NOTICES.Z');
328328

329-
final Uint8List licenseData = noticesFile?.content as Uint8List;
329+
final Uint8List? licenseData = noticesFile?.content as Uint8List?;
330330
if (licenseData == null) {
331331
return TaskResult.failure('Invalid license file.');
332332
}
@@ -368,7 +368,7 @@ Future<void> main() async {
368368

369369
modes = readonlyReleaseAssetFile.statSync().modeString();
370370
print('\nread-only.txt file access modes = $modes');
371-
if (modes != null && modes.compareTo(fileReadWriteMode) != 0) {
371+
if (modes.compareTo(fileReadWriteMode) != 0) {
372372
return TaskResult.failure('Failed to make assets user-readable and writable');
373373
}
374374

dev/devicelab/lib/framework/browser.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,6 @@ class BlinkTraceSummary {
304304
orElse: () => throw noMeasuredFramesFound(),
305305
);
306306

307-
if (firstMeasuredFrameEvent == null) {
308-
// This happens in benchmarks that do not measure frames, such as some
309-
// of the text layout benchmarks.
310-
return null;
311-
}
312-
313307
final int tabPid = firstMeasuredFrameEvent.pid!;
314308

315309
// Filter out data from unrelated processes

dev/devicelab/lib/framework/cocoon.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class AuthenticatedCocoonClient extends BaseClient {
246246
}
247247

248248
class CocoonException implements Exception {
249-
CocoonException(this.message) : assert(message != null);
249+
CocoonException(this.message);
250250

251251
/// The message to show to the issuer to explain the error.
252252
final String message;

dev/devicelab/lib/framework/devices.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DeviceException implements Exception {
1919
final String message;
2020

2121
@override
22-
String toString() => message == null ? '$DeviceException' : '$DeviceException: $message';
22+
String toString() => '$DeviceException: $message';
2323
}
2424

2525
/// Gets the artifact path relative to the current directory.

dev/devicelab/lib/framework/running_processes.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import 'package:process/process.dart';
99

1010
@immutable
1111
class RunningProcessInfo {
12-
const RunningProcessInfo(this.pid, this.commandLine, this.creationDate)
13-
: assert(pid != null),
14-
assert(commandLine != null);
12+
const RunningProcessInfo(this.pid, this.commandLine, this.creationDate);
1513

1614
final int pid;
1715
final String commandLine;
@@ -94,10 +92,6 @@ Future<Set<RunningProcessInfo>> windowsRunningProcesses(
9492
/// 2904 3/11/2019 11:01:54 AM "C:\Program Files\Android\Android Studio\jre\bin\java.exe" -Xmx1536M -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\win1\.gradle\wrapper\dists\gradle-4.10.2-all\9fahxiiecdb76a5g3aw9oi8rv\gradle-4.10.2\lib\gradle-launcher-4.10.2.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 4.10.2
9593
@visibleForTesting
9694
Iterable<RunningProcessInfo> processPowershellOutput(String output) sync* {
97-
if (output == null) {
98-
return;
99-
}
100-
10195
const int processIdHeaderSize = 'ProcessId'.length;
10296
const int creationDateHeaderStart = processIdHeaderSize + 1;
10397
late int creationDateHeaderEnd;
@@ -187,9 +181,6 @@ Iterable<RunningProcessInfo> processPsOutput(
187181
String output,
188182
String? processName,
189183
) sync* {
190-
if (output == null) {
191-
return;
192-
}
193184
bool inTableBody = false;
194185
for (String line in output.split('\n')) {
195186
if (line.trim().startsWith('STARTED')) {

dev/devicelab/lib/framework/utils.dart

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void recursiveCopy(Directory source, Directory target) {
139139
dest.writeAsBytesSync(entity.readAsBytesSync());
140140
// Preserve executable bit
141141
final String modes = entity.statSync().modeString();
142-
if (modes != null && modes.contains('x')) {
142+
if (modes.contains('x')) {
143143
makeExecutable(dest);
144144
}
145145
}
@@ -276,7 +276,6 @@ Future<Process> startProcess(
276276
bool isBot = true, // set to false to pretend not to be on a bot (e.g. to test user-facing outputs)
277277
String? workingDirectory,
278278
}) async {
279-
assert(isBot != null);
280279
final String command = '$executable ${arguments?.join(" ") ?? ""}';
281280
final String finalWorkingDirectory = workingDirectory ?? cwd;
282281
final Map<String, String> newEnvironment = Map<String, String>.from(environment ?? <String, String>{});
@@ -504,7 +503,6 @@ Future<Process> startFlutter(String command, {
504503
Map<String, String> environment = const <String, String>{},
505504
bool isBot = true, // set to false to pretend not to be on a bot (e.g. to test user-facing outputs)
506505
}) {
507-
assert(isBot != null);
508506
final List<String> args = flutterCommandArgs(command, options);
509507
return startProcess(
510508
path.join(flutterDirectory.path, 'bin', 'flutter'),
@@ -635,48 +633,6 @@ Future<void> getNewGallery(String revision, Directory galleryDir) async {
635633
});
636634
}
637635

638-
void checkNotNull(Object o1,
639-
[Object o2 = 1,
640-
Object o3 = 1,
641-
Object o4 = 1,
642-
Object o5 = 1,
643-
Object o6 = 1,
644-
Object o7 = 1,
645-
Object o8 = 1,
646-
Object o9 = 1,
647-
Object o10 = 1]) {
648-
if (o1 == null) {
649-
throw 'o1 is null';
650-
}
651-
if (o2 == null) {
652-
throw 'o2 is null';
653-
}
654-
if (o3 == null) {
655-
throw 'o3 is null';
656-
}
657-
if (o4 == null) {
658-
throw 'o4 is null';
659-
}
660-
if (o5 == null) {
661-
throw 'o5 is null';
662-
}
663-
if (o6 == null) {
664-
throw 'o6 is null';
665-
}
666-
if (o7 == null) {
667-
throw 'o7 is null';
668-
}
669-
if (o8 == null) {
670-
throw 'o8 is null';
671-
}
672-
if (o9 == null) {
673-
throw 'o9 is null';
674-
}
675-
if (o10 == null) {
676-
throw 'o10 is null';
677-
}
678-
}
679-
680636
/// Splits [from] into lines and selects those that contain [pattern].
681637
Iterable<String> grep(Pattern pattern, {required String from}) {
682638
return from.split('\n').where((String line) {

dev/devicelab/lib/tasks/perf_tests.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,10 +2042,7 @@ class _UnzipListEntry {
20422042
required this.uncompressedSize,
20432043
required this.compressedSize,
20442044
required this.path,
2045-
}) : assert(uncompressedSize != null),
2046-
assert(compressedSize != null),
2047-
assert(compressedSize <= uncompressedSize),
2048-
assert(path != null);
2045+
}) : assert(compressedSize <= uncompressedSize);
20492046

20502047
final int uncompressedSize;
20512048
final int compressedSize;

dev/devicelab/lib/tasks/web_benchmarks.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ Future<TaskResult> runWebBenchmark({ required bool useCanvasKit }) async {
161161

162162
final String namespace = '$benchmarkName.$backend';
163163
final List<String> scoreKeys = List<String>.from(profile['scoreKeys'] as List<dynamic>);
164-
if (scoreKeys == null || scoreKeys.isEmpty) {
164+
if (scoreKeys.isEmpty) {
165165
throw 'No score keys in benchmark "$benchmarkName"';
166166
}
167167
for (final String scoreKey in scoreKeys) {
168-
if (scoreKey == null || scoreKey.isEmpty) {
168+
if (scoreKey.isEmpty) {
169169
throw 'Score key is empty in benchmark "$benchmarkName". '
170170
'Received [${scoreKeys.join(', ')}]';
171171
}

0 commit comments

Comments
 (0)