From 29775f74fbb34266096405fa5f2ad78e97b30a88 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Wed, 2 May 2018 21:03:37 -0700 Subject: [PATCH] Handle pubspec.yaml files with no dependencies (#17195) Currently, `flutter update-packages --force-upgrade` will crash if it encounters a pubspec.yaml file with no dependencies (either regular or dev). The assumption that we'd never see such pubspec files is no longer valid, as we have such a file in one of our tests. --- .../lib/src/commands/update_packages.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/update_packages.dart b/packages/flutter_tools/lib/src/commands/update_packages.dart index 32a90ccfe3..41817b328a 100644 --- a/packages/flutter_tools/lib/src/commands/update_packages.dart +++ b/packages/flutter_tools/lib/src/commands/update_packages.dart @@ -656,12 +656,10 @@ class PubspecYaml { } } - // By this point we should know where to put our transitive dependencies. - // Only if there were no dependencies or dev_dependencies sections could - // we get here with these still null, and we should not have any such files - // in our repo. - assert(endOfDirectDependencies != null); - assert(endOfDevDependencies != null); + // If there are no dependencies or dev_dependencies sections, these will be + // null. We have such files in our tests, so account for them here. + endOfDirectDependencies ??= output.length; + endOfDevDependencies ??= output.length; // Now include all the transitive dependencies and transitive dev dependencies. // The blocks of text to insert for each dependency section.