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

Skip to content

Remove unnecessary null checks in dev/devicelab #118842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Future<void> main() async {

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

Expand Down Expand Up @@ -347,7 +347,7 @@ Future<void> main() async {

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

Expand Down
6 changes: 3 additions & 3 deletions dev/devicelab/bin/tasks/module_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Future<void> main() async {

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

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

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

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

Expand Down
6 changes: 0 additions & 6 deletions dev/devicelab/lib/framework/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,6 @@ class BlinkTraceSummary {
orElse: () => throw noMeasuredFramesFound(),
);

if (firstMeasuredFrameEvent == null) {
// This happens in benchmarks that do not measure frames, such as some
// of the text layout benchmarks.
return null;
}

final int tabPid = firstMeasuredFrameEvent.pid!;

// Filter out data from unrelated processes
Expand Down
2 changes: 1 addition & 1 deletion dev/devicelab/lib/framework/cocoon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class AuthenticatedCocoonClient extends BaseClient {
}

class CocoonException implements Exception {
CocoonException(this.message) : assert(message != null);
CocoonException(this.message);

/// The message to show to the issuer to explain the error.
final String message;
Expand Down
2 changes: 1 addition & 1 deletion dev/devicelab/lib/framework/devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DeviceException implements Exception {
final String message;

@override
String toString() => message == null ? '$DeviceException' : '$DeviceException: $message';
String toString() => '$DeviceException: $message';
}

/// Gets the artifact path relative to the current directory.
Expand Down
11 changes: 1 addition & 10 deletions dev/devicelab/lib/framework/running_processes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import 'package:process/process.dart';

@immutable
class RunningProcessInfo {
const RunningProcessInfo(this.pid, this.commandLine, this.creationDate)
: assert(pid != null),
assert(commandLine != null);
const RunningProcessInfo(this.pid, this.commandLine, this.creationDate);

final int pid;
final String commandLine;
Expand Down Expand Up @@ -94,10 +92,6 @@ Future<Set<RunningProcessInfo>> windowsRunningProcesses(
/// 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
@visibleForTesting
Iterable<RunningProcessInfo> processPowershellOutput(String output) sync* {
if (output == null) {
return;
}

const int processIdHeaderSize = 'ProcessId'.length;
const int creationDateHeaderStart = processIdHeaderSize + 1;
late int creationDateHeaderEnd;
Expand Down Expand Up @@ -187,9 +181,6 @@ Iterable<RunningProcessInfo> processPsOutput(
String output,
String? processName,
) sync* {
if (output == null) {
return;
}
bool inTableBody = false;
for (String line in output.split('\n')) {
if (line.trim().startsWith('STARTED')) {
Expand Down
46 changes: 1 addition & 45 deletions dev/devicelab/lib/framework/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void recursiveCopy(Directory source, Directory target) {
dest.writeAsBytesSync(entity.readAsBytesSync());
// Preserve executable bit
final String modes = entity.statSync().modeString();
if (modes != null && modes.contains('x')) {
if (modes.contains('x')) {
makeExecutable(dest);
}
}
Expand Down Expand Up @@ -276,7 +276,6 @@ Future<Process> startProcess(
bool isBot = true, // set to false to pretend not to be on a bot (e.g. to test user-facing outputs)
String? workingDirectory,
}) async {
assert(isBot != null);
final String command = '$executable ${arguments?.join(" ") ?? ""}';
final String finalWorkingDirectory = workingDirectory ?? cwd;
final Map<String, String> newEnvironment = Map<String, String>.from(environment ?? <String, String>{});
Expand Down Expand Up @@ -504,7 +503,6 @@ Future<Process> startFlutter(String command, {
Map<String, String> environment = const <String, String>{},
bool isBot = true, // set to false to pretend not to be on a bot (e.g. to test user-facing outputs)
}) {
assert(isBot != null);
final List<String> args = flutterCommandArgs(command, options);
return startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'),
Expand Down Expand Up @@ -635,48 +633,6 @@ Future<void> getNewGallery(String revision, Directory galleryDir) async {
});
}

void checkNotNull(Object o1,
[Object o2 = 1,
Object o3 = 1,
Object o4 = 1,
Object o5 = 1,
Object o6 = 1,
Object o7 = 1,
Object o8 = 1,
Object o9 = 1,
Object o10 = 1]) {
if (o1 == null) {
throw 'o1 is null';
}
if (o2 == null) {
throw 'o2 is null';
}
if (o3 == null) {
throw 'o3 is null';
}
if (o4 == null) {
throw 'o4 is null';
}
if (o5 == null) {
throw 'o5 is null';
}
if (o6 == null) {
throw 'o6 is null';
}
if (o7 == null) {
throw 'o7 is null';
}
if (o8 == null) {
throw 'o8 is null';
}
if (o9 == null) {
throw 'o9 is null';
}
if (o10 == null) {
throw 'o10 is null';
}
}

/// Splits [from] into lines and selects those that contain [pattern].
Iterable<String> grep(Pattern pattern, {required String from}) {
return from.split('\n').where((String line) {
Expand Down
5 changes: 1 addition & 4 deletions dev/devicelab/lib/tasks/perf_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2042,10 +2042,7 @@ class _UnzipListEntry {
required this.uncompressedSize,
required this.compressedSize,
required this.path,
}) : assert(uncompressedSize != null),
assert(compressedSize != null),
assert(compressedSize <= uncompressedSize),
assert(path != null);
}) : assert(compressedSize <= uncompressedSize);

final int uncompressedSize;
final int compressedSize;
Expand Down
4 changes: 2 additions & 2 deletions dev/devicelab/lib/tasks/web_benchmarks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ Future<TaskResult> runWebBenchmark({ required bool useCanvasKit }) async {

final String namespace = '$benchmarkName.$backend';
final List<String> scoreKeys = List<String>.from(profile['scoreKeys'] as List<dynamic>);
if (scoreKeys == null || scoreKeys.isEmpty) {
if (scoreKeys.isEmpty) {
throw 'No score keys in benchmark "$benchmarkName"';
}
for (final String scoreKey in scoreKeys) {
if (scoreKey == null || scoreKey.isEmpty) {
if (scoreKey.isEmpty) {
throw 'Score key is empty in benchmark "$benchmarkName". '
'Received [${scoreKeys.join(', ')}]';
}
Expand Down