Commit 2ec6b31a authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Fix potential NPE in iOS doctor check (#8016)

* Fix potential NPE in iOS doctor check

In case Xcode is not installed, the xcode-select path may be null.

* fixup! Fix potential NPE in iOS doctor check
parent b180caae
...@@ -87,7 +87,7 @@ class IOSWorkflow extends DoctorValidator implements Workflow { ...@@ -87,7 +87,7 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
} }
} else { } else {
xcodeStatus = ValidationType.missing; xcodeStatus = ValidationType.missing;
if (xcode.xcodeSelectPath.isEmpty) { if (xcode.xcodeSelectPath == null || xcode.xcodeSelectPath.isEmpty) {
messages.add(new ValidationMessage.error( messages.add(new ValidationMessage.error(
'Xcode not installed; this is necessary for iOS development.\n' 'Xcode not installed; this is necessary for iOS development.\n'
'Download at https://developer.apple.com/xcode/download/.' 'Download at https://developer.apple.com/xcode/download/.'
......
...@@ -29,8 +29,8 @@ class Xcode { ...@@ -29,8 +29,8 @@ class Xcode {
_eulaSigned = false; _eulaSigned = false;
try { try {
_xcodeSelectPath = runSync(<String>['xcode-select', '--print-path']); _xcodeSelectPath = runSync(<String>['xcode-select', '--print-path'])?.trim();
if (_xcodeSelectPath == null || _xcodeSelectPath.trim().isEmpty) { if (_xcodeSelectPath == null || _xcodeSelectPath.isEmpty) {
_isInstalled = false; _isInstalled = false;
return; return;
} }
......
...@@ -20,7 +20,7 @@ void main() { ...@@ -20,7 +20,7 @@ void main() {
testUsingContext('Emit missing status when nothing is installed', () async { testUsingContext('Emit missing status when nothing is installed', () async {
when(xcode.isInstalled).thenReturn(false); when(xcode.isInstalled).thenReturn(false);
when(xcode.xcodeSelectPath).thenReturn(''); when(xcode.xcodeSelectPath).thenReturn(null);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget() IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget()
..hasPythonSixModule = false ..hasPythonSixModule = false
..hasHomebrew = false ..hasHomebrew = false
...@@ -31,7 +31,7 @@ void main() { ...@@ -31,7 +31,7 @@ void main() {
testUsingContext('Emits partial status when Xcode is not installed', () async { testUsingContext('Emits partial status when Xcode is not installed', () async {
when(xcode.isInstalled).thenReturn(false); when(xcode.isInstalled).thenReturn(false);
when(xcode.xcodeSelectPath).thenReturn(''); when(xcode.xcodeSelectPath).thenReturn(null);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget(); IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget();
ValidationResult result = await workflow.validate(); ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial); expect(result.type, ValidationType.partial);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment