Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1155693004: Fix NPE in building element model when part URI could not be resolved (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/dart.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index 29ab152677f6b3d4d48e8e950f5474f1af1c75d5..dda846ed87436f6e8a4b3fbfaff581504faab386 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -1322,38 +1322,40 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask {
Source partSource = partDirective.source;
hasPartDirective = true;
CompilationUnit partUnit = partUnitMap[partSource];
- CompilationUnitElementImpl partElement = partUnit.element;
- partElement.uriOffset = partUri.offset;
- partElement.uriEnd = partUri.end;
- partElement.uri = partDirective.uriContent;
- //
- // Validate that the part contains a part-of directive with the same
- // name as the library.
- //
- String partLibraryName =
- _getPartLibraryName(partSource, partUnit, directivesToResolve);
- if (partLibraryName == null) {
- errors.add(new AnalysisError(librarySource, partUri.offset,
- partUri.length, CompileTimeErrorCode.PART_OF_NON_PART,
- [partUri.toSource()]));
- } else if (libraryNameNode == null) {
- if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) {
- partsLibraryName = partLibraryName;
- } else if (partsLibraryName != partLibraryName) {
- partsLibraryName = null;
+ if (partUnit != null) {
+ CompilationUnitElementImpl partElement = partUnit.element;
+ partElement.uriOffset = partUri.offset;
+ partElement.uriEnd = partUri.end;
+ partElement.uri = partDirective.uriContent;
+ //
+ // Validate that the part contains a part-of directive with the same
+ // name as the library.
+ //
+ String partLibraryName =
+ _getPartLibraryName(partSource, partUnit, directivesToResolve);
+ if (partLibraryName == null) {
+ errors.add(new AnalysisError(librarySource, partUri.offset,
+ partUri.length, CompileTimeErrorCode.PART_OF_NON_PART,
+ [partUri.toSource()]));
+ } else if (libraryNameNode == null) {
+ if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) {
+ partsLibraryName = partLibraryName;
+ } else if (partsLibraryName != partLibraryName) {
+ partsLibraryName = null;
+ }
+ } else if (libraryNameNode.name != partLibraryName) {
+ errors.add(new AnalysisError(librarySource, partUri.offset,
+ partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [
+ libraryNameNode.name,
+ partLibraryName
+ ]));
}
- } else if (libraryNameNode.name != partLibraryName) {
- errors.add(new AnalysisError(librarySource, partUri.offset,
- partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [
- libraryNameNode.name,
- partLibraryName
- ]));
- }
- if (entryPoint == null) {
- entryPoint = _findEntryPoint(partElement);
+ if (entryPoint == null) {
+ entryPoint = _findEntryPoint(partElement);
+ }
+ directive.element = partElement;
+ sourcedCompilationUnits.add(partElement);
}
- directive.element = partElement;
- sourcedCompilationUnits.add(partElement);
}
}
if (hasPartDirective && libraryNameNode == null) {
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698