Skip to content

Commit cadb264

Browse files
[flutter_tools] Catch more general XmlException rather than XmlParserException (#107574)
1 parent b26346f commit cadb264

7 files changed

+20
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
139139
XmlDocument document;
140140
try {
141141
document = XmlDocument.parse(manifestString);
142-
} on XmlParserException catch (exception) {
142+
} on XmlException catch (exception) {
143143
String manifestLocation;
144144
if (androidProject.isUsingGradle) {
145145
manifestLocation = fileSystem.path.join(androidProject.hostAppGradleRoot.path, 'app', 'src', 'main', 'AndroidManifest.xml');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DeferredComponentsGenSnapshotValidator extends DeferredComponentsValidator
8484
XmlDocument document;
8585
try {
8686
document = XmlDocument.parse(appManifestFile.readAsStringSync());
87-
} on XmlParserException {
87+
} on XmlException {
8888
invalidFiles[appManifestFile.path] = 'Error parsing $appManifestFile '
8989
'Please ensure that the android manifest is a valid XML document and '
9090
'try again.';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class DeferredComponentsPrebuildValidator extends DeferredComponentsValidator {
136136
XmlDocument document;
137137
try {
138138
document = XmlDocument.parse(stringRes.readAsStringSync());
139-
} on XmlParserException {
139+
} on XmlException {
140140
invalidFiles[stringRes.path] = 'Error parsing $stringRes '
141141
'Please ensure that the strings.xml is a valid XML document and '
142142
'try again.';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ String _getLocalArtifactVersion(String pomPath, FileSystem fileSystem) {
958958
XmlDocument document;
959959
try {
960960
document = XmlDocument.parse(pomFile.readAsStringSync());
961-
} on XmlParserException {
961+
} on XmlException {
962962
throwToolExit(
963963
'Error parsing $pomPath. Please ensure that this is a valid XML document.'
964964
);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ bool androidManifestHasNameVariable(final Directory projectDir) {
9393
XmlDocument document;
9494
try {
9595
document = XmlDocument.parse(manifestFile.readAsStringSync());
96-
} on XmlParserException {
97-
return false;
98-
} on XmlTagException {
96+
} on XmlException {
9997
return false;
10098
} on FileSystemException {
10199
return false;

packages/flutter_tools/lib/src/project.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ The detected reason was:
647647
XmlDocument document;
648648
try {
649649
document = XmlDocument.parse(appManifestFile.readAsStringSync());
650-
} on XmlParserException {
650+
} on XmlException {
651651
throwToolExit('Error parsing $appManifestFile '
652652
'Please ensure that the android manifest is a valid XML document and try again.');
653653
} on FileSystemException {

packages/flutter_tools/test/general.shard/project_test.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ void main() {
188188
await project.regeneratePlatformSpecificTooling();
189189
expectExists(project.android.hostAppGradleRoot.childFile('local.properties'));
190190
});
191+
_testInMemory('checkForDeprecation fails on invalid android app manifest file', () async {
192+
// This is not a valid Xml document
193+
const String invalidManifest = '<manifest></application>';
194+
final FlutterProject project = await someProject(androidManifestOverride: invalidManifest);
195+
196+
expect(
197+
() => project.checkForDeprecation(deprecationBehavior: DeprecationBehavior.ignore),
198+
throwsToolExit(message: 'Please ensure that the android manifest is a valid XML document and try again.'),
199+
);
200+
});
191201
_testInMemory('Android project not on v2 embedding shows a warning', () async {
192202
final FlutterProject project = await someProject();
193203
// The default someProject with an empty <manifest> already indicates
@@ -769,7 +779,9 @@ apply plugin: 'kotlin-android'
769779
});
770780
}
771781

772-
Future<FlutterProject> someProject() async {
782+
Future<FlutterProject> someProject({
783+
String androidManifestOverride,
784+
}) async {
773785
final Directory directory = globals.fs.directory('some_project');
774786
directory.childDirectory('.dart_tool')
775787
.childFile('package_config.json')
@@ -781,7 +793,7 @@ Future<FlutterProject> someProject() async {
781793
..createSync(recursive: true);
782794
androidDirectory
783795
.childFile('AndroidManifest.xml')
784-
.writeAsStringSync('<manifest></manifest>');
796+
.writeAsStringSync(androidManifestOverride ?? '<manifest></manifest>');
785797
return FlutterProject.fromDirectory(directory);
786798
}
787799

0 commit comments

Comments
 (0)