Skip to content

Commit 9203448

Browse files
author
Jonah Williams
authored
[flutter_tool] partial null safety migration of tool source code (#105798)
1 parent a7ddb9b commit 9203448

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1932
-2025
lines changed

dev/bots/test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ Future<void> _runGeneralToolTests() async {
339339
_toolsPath,
340340
testPaths: <String>[path.join('test', 'general.shard')],
341341
enableFlutterToolAsserts: false,
342+
342343
// Detect unit test time regressions (poor time delay handling, etc).
343344
// This overrides the 15 minute default for tools tests.
344345
// See the README.md and dart_test.yaml files in the flutter_tools package.

packages/flutter_tools/lib/executable.dart

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
7-
import 'package:meta/meta.dart';
8-
95
import 'runner.dart' as runner;
106
import 'src/artifacts.dart';
117
import 'src/base/context.dart';
@@ -110,7 +106,7 @@ Future<void> main(List<String> args) async {
110106
// devtools source code.
111107
DevtoolsLauncher: () => DevtoolsServerLauncher(
112108
processManager: globals.processManager,
113-
dartExecutable: globals.artifacts.getHostArtifact(HostArtifact.engineDartBinary).path,
109+
dartExecutable: globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path,
114110
logger: globals.logger,
115111
botDetector: globals.botDetector,
116112
),
@@ -134,8 +130,8 @@ Future<void> main(List<String> args) async {
134130
}
135131

136132
List<FlutterCommand> generateCommands({
137-
@required bool verboseHelp,
138-
@required bool verbose,
133+
required bool verboseHelp,
134+
required bool verbose,
139135
}) => <FlutterCommand>[
140136
AnalyzeCommand(
141137
verboseHelp: verboseHelp,
@@ -144,7 +140,7 @@ List<FlutterCommand> generateCommands({
144140
processManager: globals.processManager,
145141
logger: globals.logger,
146142
terminal: globals.terminal,
147-
artifacts: globals.artifacts,
143+
artifacts: globals.artifacts!,
148144
),
149145
AssembleCommand(verboseHelp: verboseHelp, buildSystem: globals.buildSystem),
150146
AttachCommand(verboseHelp: verboseHelp),
@@ -210,9 +206,9 @@ List<FlutterCommand> generateCommands({
210206
/// Our logger class hierarchy and runtime requirements are overly complicated.
211207
class LoggerFactory {
212208
LoggerFactory({
213-
@required Terminal terminal,
214-
@required Stdio stdio,
215-
@required OutputPreferences outputPreferences,
209+
required Terminal terminal,
210+
required Stdio stdio,
211+
required OutputPreferences outputPreferences,
216212
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
217213
}) : _terminal = terminal,
218214
_stdio = stdio,
@@ -226,11 +222,11 @@ class LoggerFactory {
226222

227223
/// Create the appropriate logger for the current platform and configuration.
228224
Logger createLogger({
229-
@required bool verbose,
230-
@required bool prefixedErrors,
231-
@required bool machine,
232-
@required bool daemon,
233-
@required bool windows,
225+
required bool verbose,
226+
required bool prefixedErrors,
227+
required bool machine,
228+
required bool daemon,
229+
required bool windows,
234230
}) {
235231
Logger logger;
236232
if (windows) {

packages/flutter_tools/lib/runner.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
5+
66

77
import 'dart:async';
88

@@ -31,9 +31,9 @@ Future<int> run(
3131
bool muteCommandLogging = false,
3232
bool verbose = false,
3333
bool verboseHelp = false,
34-
bool reportCrashes,
35-
String flutterVersion,
36-
Map<Type, Generator> overrides,
34+
bool? reportCrashes,
35+
String? flutterVersion,
36+
Map<Type, Generator>? overrides,
3737
}) async {
3838
if (muteCommandLogging) {
3939
// Remove the verbose option; for help and doctor, users don't need to see
@@ -55,8 +55,8 @@ Future<int> run(
5555
);
5656

5757
String getVersion() => flutterVersion ?? globals.flutterVersion.getVersionString(redactUnknownBranches: true);
58-
Object firstError;
59-
StackTrace firstStackTrace;
58+
Object? firstError;
59+
StackTrace? firstStackTrace;
6060
return runZoned<Future<int>>(() async {
6161
try {
6262
await runner.run(args);
@@ -74,22 +74,22 @@ Future<int> run(
7474
// This catches all exceptions to send to crash logging, etc.
7575
firstError = error;
7676
firstStackTrace = stackTrace;
77-
return _handleToolError(error, stackTrace, verbose, args, reportCrashes, getVersion);
77+
return _handleToolError(error, stackTrace, verbose, args, reportCrashes!, getVersion);
7878
}
7979
}, onError: (Object error, StackTrace stackTrace) async { // ignore: deprecated_member_use
8080
// If sending a crash report throws an error into the zone, we don't want
8181
// to re-try sending the crash report with *that* error. Rather, we want
8282
// to send the original error that triggered the crash report.
8383
firstError ??= error;
8484
firstStackTrace ??= stackTrace;
85-
await _handleToolError(firstError, firstStackTrace, verbose, args, reportCrashes, getVersion);
85+
await _handleToolError(firstError!, firstStackTrace, verbose, args, reportCrashes!, getVersion);
8686
});
8787
}, overrides: overrides);
8888
}
8989

9090
Future<int> _handleToolError(
91-
dynamic error,
92-
StackTrace stackTrace,
91+
Object error,
92+
StackTrace? stackTrace,
9393
bool verbose,
9494
List<String> args,
9595
bool reportCrashes,
@@ -102,7 +102,7 @@ Future<int> _handleToolError(
102102
return _exit(64);
103103
} else if (error is ToolExit) {
104104
if (error.message != null) {
105-
globals.printError(error.message);
105+
globals.printError(error.message!);
106106
}
107107
if (verbose) {
108108
globals.printError('\n$stackTrace\n');
@@ -138,7 +138,7 @@ Future<int> _handleToolError(
138138
);
139139
await crashReportSender.sendReport(
140140
error: error,
141-
stackTrace: stackTrace,
141+
stackTrace: stackTrace!,
142142
getFlutterVersion: getFlutterVersion,
143143
command: args.join(' '),
144144
);
@@ -159,17 +159,17 @@ Future<int> _handleToolError(
159159
final CrashDetails details = CrashDetails(
160160
command: _crashCommand(args),
161161
error: error,
162-
stackTrace: stackTrace,
162+
stackTrace: stackTrace!,
163163
doctorText: doctorText,
164164
);
165165
final File file = await _createLocalCrashReport(details);
166-
await globals.crashReporter.informUser(details, file);
166+
await globals.crashReporter!.informUser(details, file);
167167

168168
return _exit(1);
169169
// This catch catches all exceptions to ensure the message below is printed.
170-
} catch (error) { // ignore: avoid_catches_without_on_clauses
170+
} catch (error, st) { // ignore: avoid_catches_without_on_clauses
171171
globals.stdio.stderrWrite(
172-
'Unable to generate crash report due to secondary error: $error\n'
172+
'Unable to generate crash report due to secondary error: $error\n$st\n'
173173
'${globals.userMessages.flutterToolBugInstructions}\n',
174174
);
175175
// Any exception thrown here (including one thrown by `_exit()`) will
@@ -241,7 +241,7 @@ Future<int> _exit(int code) async {
241241
}
242242

243243
// Run shutdown hooks before flushing logs
244-
await globals.shutdownHooks.runShutdownHooks();
244+
await globals.shutdownHooks!.runShutdownHooks();
245245

246246
final Completer<void> completer = Completer<void>();
247247

packages/flutter_tools/lib/src/android/android_workflow.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class AndroidValidator extends DoctorValidator {
271271
/// SDK have been accepted.
272272
class AndroidLicenseValidator extends DoctorValidator {
273273
AndroidLicenseValidator({
274-
required AndroidSdk androidSdk,
274+
required AndroidSdk? androidSdk,
275275
required Platform platform,
276276
required OperatingSystemUtils operatingSystemUtils,
277277
required FileSystem fileSystem,
@@ -291,7 +291,7 @@ class AndroidLicenseValidator extends DoctorValidator {
291291
_userMessages = userMessages,
292292
super('Android license subvalidator');
293293

294-
final AndroidSdk _androidSdk;
294+
final AndroidSdk? _androidSdk;
295295
final AndroidStudio? _androidStudio;
296296
final Stdio _stdio;
297297
final OperatingSystemUtils _operatingSystemUtils;
@@ -309,13 +309,13 @@ class AndroidLicenseValidator extends DoctorValidator {
309309
final List<ValidationMessage> messages = <ValidationMessage>[];
310310

311311
// Match pre-existing early termination behavior
312-
if (_androidSdk == null || _androidSdk.latestVersion == null ||
313-
_androidSdk.validateSdkWellFormed().isNotEmpty ||
312+
if (_androidSdk == null || _androidSdk?.latestVersion == null ||
313+
_androidSdk!.validateSdkWellFormed().isNotEmpty ||
314314
! await _checkJavaVersionNoOutput()) {
315315
return ValidationResult(ValidationType.missing, messages);
316316
}
317317

318-
final String sdkVersionText = _userMessages.androidStatusInfo(_androidSdk.latestVersion!.buildToolsVersionName);
318+
final String sdkVersionText = _userMessages.androidStatusInfo(_androidSdk!.latestVersion!.buildToolsVersionName);
319319

320320
// Check for licenses.
321321
switch (await licensesAccepted) {
@@ -392,8 +392,8 @@ class AndroidLicenseValidator extends DoctorValidator {
392392

393393
try {
394394
final Process process = await _processManager.start(
395-
<String>[_androidSdk.sdkManagerPath!, '--licenses'],
396-
environment: _androidSdk.sdkManagerEnv,
395+
<String>[_androidSdk!.sdkManagerPath!, '--licenses'],
396+
environment: _androidSdk!.sdkManagerEnv,
397397
);
398398
process.stdin.write('n\n');
399399
// We expect logcat streams to occasionally contain invalid utf-8,
@@ -432,8 +432,8 @@ class AndroidLicenseValidator extends DoctorValidator {
432432

433433
try {
434434
final Process process = await _processManager.start(
435-
<String>[_androidSdk.sdkManagerPath!, '--licenses'],
436-
environment: _androidSdk.sdkManagerEnv,
435+
<String>[_androidSdk!.sdkManagerPath!, '--licenses'],
436+
environment: _androidSdk!.sdkManagerEnv,
437437
);
438438

439439
// The real stdin will never finish streaming. Pipe until the child process
@@ -463,15 +463,15 @@ class AndroidLicenseValidator extends DoctorValidator {
463463
return exitCode == 0;
464464
} on ProcessException catch (e) {
465465
throwToolExit(_userMessages.androidCannotRunSdkManager(
466-
_androidSdk.sdkManagerPath ?? '',
466+
_androidSdk?.sdkManagerPath ?? '',
467467
e.toString(),
468468
_platform,
469469
));
470470
}
471471
}
472472

473473
bool _canRunSdkManager() {
474-
final String? sdkManagerPath = _androidSdk.sdkManagerPath;
474+
final String? sdkManagerPath = _androidSdk?.sdkManagerPath;
475475
if (sdkManagerPath == null) {
476476
return false;
477477
}

packages/flutter_tools/lib/src/android/application_package.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
9797
/// Creates a new AndroidApk based on the information in the Android manifest.
9898
static Future<AndroidApk?> fromAndroidProject(
9999
AndroidProject androidProject, {
100-
required AndroidSdk androidSdk,
100+
required AndroidSdk? androidSdk,
101101
required ProcessManager processManager,
102102
required UserMessages userMessages,
103103
required ProcessUtils processUtils,
@@ -113,7 +113,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
113113
// the application Id, so we need to look at what was actually built.
114114
return AndroidApk.fromApk(
115115
apkFile,
116-
androidSdk: androidSdk,
116+
androidSdk: androidSdk!,
117117
processManager: processManager,
118118
logger: logger,
119119
userMessages: userMessages,

packages/flutter_tools/lib/src/base/utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ class SettingsFile {
157157

158158
/// Given a data structure which is a Map of String to dynamic values, return
159159
/// the same structure (`Map<String, dynamic>`) with the correct runtime types.
160-
Map<String, dynamic>? castStringKeyedMap(dynamic untyped) {
160+
Map<String, Object?>? castStringKeyedMap(Object? untyped) {
161161
final Map<dynamic, dynamic>? map = untyped as Map<dynamic, dynamic>?;
162-
return map?.cast<String, dynamic>();
162+
return map?.cast<String, Object?>();
163163
}
164164

165165
/// Smallest column that will be used for text wrapping. If the requested column

0 commit comments

Comments
 (0)