Guard analysis server against missing .instrumentation directory location on disk

Currently if analysis server fails to resolve this directory, it will
crash the entire process with

NoSuchMethodError: The method 'getChild' was called on null.

_readUuid() was already failing over to generating a new random
identifier if it was either unable to find a uuid.txt file or
create one, so this change just triggers that behavior additionally
in the case that the parent directory is missing.

R=brianwilkerson@google.com

Change-Id: Ieafde2df5afd7e30a3830f241af02bf305c911ec
Reviewed-on: https://dart-review.googlesource.com/c/88428
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Ari Aye <ariaye@google.com>
diff --git a/pkg/analysis_server/lib/src/server/driver.dart b/pkg/analysis_server/lib/src/server/driver.dart
index 3f6e67d..21d5cc8 100644
--- a/pkg/analysis_server/lib/src/server/driver.dart
+++ b/pkg/analysis_server/lib/src/server/driver.dart
@@ -740,10 +740,12 @@
    * Read the UUID from disk, generating and storing a new one if necessary.
    */
   String _readUuid(InstrumentationService service) {
-    File uuidFile = new File(PhysicalResourceProvider.INSTANCE
-        .getStateLocation('.instrumentation')
-        .getChild('uuid.txt')
-        .path);
+    final instrumentationLocation =
+        PhysicalResourceProvider.INSTANCE.getStateLocation('.instrumentation');
+    if (instrumentationLocation == null) {
+      return _generateUuidString();
+    }
+    File uuidFile = new File(instrumentationLocation.getChild('uuid.txt').path);
     try {
       if (uuidFile.existsSync()) {
         String uuid = uuidFile.readAsStringSync();
@@ -754,9 +756,7 @@
     } catch (exception, stackTrace) {
       service.logPriorityException(exception, stackTrace);
     }
-    int millisecondsSinceEpoch = new DateTime.now().millisecondsSinceEpoch;
-    int random = new Random().nextInt(0x3fffffff);
-    String uuid = '$millisecondsSinceEpoch$random';
+    String uuid = _generateUuidString();
     try {
       uuidFile.parent.createSync(recursive: true);
       uuidFile.writeAsStringSync(uuid);
@@ -769,6 +769,15 @@
   }
 
   /**
+   * Constructs a uuid combining the current date and a random integer.
+   */
+  String _generateUuidString() {
+    int millisecondsSinceEpoch = new DateTime.now().millisecondsSinceEpoch;
+    int random = new Random().nextInt(0x3fffffff);
+    return '$millisecondsSinceEpoch$random';
+  }
+
+  /**
    * Perform log files rolling.
    *
    * Rename existing files with names `[path].(x)` to `[path].(x+1)`.