Skip to content

Commit

Permalink
Check for importedLibrary is null in importLibraryElement().
Browse files Browse the repository at this point in the history
I see it in crashes sometimes.

R=brianwilkerson@google.com, pquitslund@google.com

Change-Id: I734d78f0e71c5985c7833fcf6e439fd4c48a5899
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139601
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Mar 15, 2020
1 parent eff5548 commit 7079c49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ abstract class ExportElement implements Element, UriReferencedElement {
List<NamespaceCombinator> get combinators;

/// Return the library that is exported from this library by this export
/// directive.
/// directive, or `null` if the URI has invalid syntax or cannot be resolved.
LibraryElement get exportedLibrary;
}

Expand Down Expand Up @@ -1246,7 +1246,7 @@ abstract class ImportElement implements Element, UriReferencedElement {
List<NamespaceCombinator> get combinators;

/// Return the library that is imported into this library by this import
/// directive.
/// directive, or `null` if the URI has invalid syntax or cannot be resolved.
LibraryElement get importedLibrary;

/// Return `true` if this import is for a deferred library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,8 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
}

for (var import in resolvedUnit.libraryElement.imports) {
if (import.importedLibrary.source.uri == uri) {
var importedLibrary = import.importedLibrary;
if (importedLibrary != null && importedLibrary.source.uri == uri) {
return ImportLibraryElementResultImpl(import.prefix?.name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ import 'package:test/b.dart';
);
}

Future<void> test_withoutPrefix_hasInvalidImport() async {
newFile('/home/test/lib/a.dart', content: 'class A {}');

await _assertImportLibraryElement(
initialCode: r'''
import ':[invalidUri]';
import 'package:test/a.dart';
''',
uriStr: 'package:test/a.dart',
name: 'A',
);
}

Future<void> test_withoutPrefix_referencedNames_sameElements() async {
newFile('/home/test/lib/a.dart', content: r'''
class A {}
Expand Down

0 comments on commit 7079c49

Please sign in to comment.