Make frontend_server initialize from dill work again

It has probably been broken since
94a6a48edd838b0b6586e65073d5d742ddb54fb5.

Change-Id: I200b9ab6b2213a198d2fd4b396b0e501dc79273e
Reviewed-on: https://dart-review.googlesource.com/60241
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Peter von der Ahé <ahe@google.com>
diff --git a/pkg/vm/lib/frontend_server.dart b/pkg/vm/lib/frontend_server.dart
index e484146..2993e42 100644
--- a/pkg/vm/lib/frontend_server.dart
+++ b/pkg/vm/lib/frontend_server.dart
@@ -373,39 +373,39 @@
     // be invalidated by the normal approach anyway.
     if (_generator.initialized) return null;
 
+    final File f = new File(_initializeFromDill);
+    if (!f.existsSync()) return null;
+
+    Component component;
     try {
-      final File f = new File(_initializeFromDill);
-      if (!f.existsSync()) return null;
+      component = loadComponentSourceFromBytes(f.readAsBytesSync());
+    } catch (e) {
+      // If we cannot load the dill file we shouldn't initialize from it.
+      _generator = _createGenerator(null);
+      return null;
+    }
 
-      final Component component =
-          loadComponentSourceFromBytes(f.readAsBytesSync());
-      for (Uri uri in component.uriToSource.keys) {
-        if ('$uri' == '') continue;
+    for (Uri uri in component.uriToSource.keys) {
+      if (uri == null || '$uri' == '') continue;
 
-        final List<int> oldBytes = component.uriToSource[uri].source;
-        final FileSystemEntity entity =
-            _compilerOptions.fileSystem.entityForUri(uri);
-        if (!await entity.exists()) {
+      final List<int> oldBytes = component.uriToSource[uri].source;
+      final FileSystemEntity entity =
+          _compilerOptions.fileSystem.entityForUri(uri);
+      if (!await entity.exists()) {
+        _generator.invalidate(uri);
+        continue;
+      }
+      final List<int> newBytes = await entity.readAsBytes();
+      if (oldBytes.length != newBytes.length) {
+        _generator.invalidate(uri);
+        continue;
+      }
+      for (int i = 0; i < oldBytes.length; ++i) {
+        if (oldBytes[i] != newBytes[i]) {
           _generator.invalidate(uri);
           continue;
         }
-        final List<int> newBytes = await entity.readAsBytes();
-        if (oldBytes.length != newBytes.length) {
-          _generator.invalidate(uri);
-          continue;
-        }
-        for (int i = 0; i < oldBytes.length; ++i) {
-          if (oldBytes[i] != newBytes[i]) {
-            _generator.invalidate(uri);
-            continue;
-          }
-        }
       }
-    } catch (e) {
-      // If there's a failure in the above block we might not have invalidated
-      // correctly. Create a new generator that doesn't initialize from dill to
-      // avoid missing any changes.
-      _generator = _createGenerator(null);
     }
   }