Fix an NPE in Variables when there are no decorated types in a given file

Change-Id: I4258becb60509b3dd0facfb2731be532464f665c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106947
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/nnbd_migration/lib/src/variables.dart b/pkg/nnbd_migration/lib/src/variables.dart
index 9a8e653..03a2055 100644
--- a/pkg/nnbd_migration/lib/src/variables.dart
+++ b/pkg/nnbd_migration/lib/src/variables.dart
@@ -33,8 +33,12 @@
   @override
   DecoratedType decoratedTypeAnnotation(
       Source source, TypeAnnotation typeAnnotation) {
-    return _decoratedTypeAnnotations[source]
-        [_uniqueOffsetForTypeAnnotation(typeAnnotation)];
+    var annotationsInSource = _decoratedTypeAnnotations[source];
+    if (annotationsInSource == null) {
+      throw StateError('No declarated type annotations in ${source.fullName}; '
+          'expected one for ${typeAnnotation.toSource()}');
+    }
+    return annotationsInSource[_uniqueOffsetForTypeAnnotation(typeAnnotation)];
   }
 
   Map<Source, List<PotentialModification>> getPotentialModifications() =>