Fix for NPE if subscribing for errors in a not analyzed file.
R=brianwilkerson@google.com BUG= Review URL: https://codereview.chromium.org//398513002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@38238 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -470,12 +470,18 @@ class AnalysisServer {
|
||||
Set<String> todoFiles = oldFiles != null ? newFiles.difference(oldFiles) : newFiles;
|
||||
for (String file in todoFiles) {
|
||||
Source source = getSource(file);
|
||||
// prepare context
|
||||
AnalysisContext context = getAnalysisContext(file);
|
||||
if (context == null) {
|
||||
continue;
|
||||
}
|
||||
// errors
|
||||
if (service == AnalysisService.ERRORS) {
|
||||
LineInfo lineInfo = context.getLineInfo(source);
|
||||
List<AnalysisError> errors = context.getErrors(source).errors;
|
||||
sendAnalysisNotificationErrors(this, file, lineInfo, errors);
|
||||
if (lineInfo != null) {
|
||||
List<AnalysisError> errors = context.getErrors(source).errors;
|
||||
sendAnalysisNotificationErrors(this, file, lineInfo, errors);
|
||||
}
|
||||
}
|
||||
// Dart unit notifications.
|
||||
if (AnalysisEngine.isDartFileName(file)) {
|
||||
|
||||
@@ -325,6 +325,19 @@ void test_setSubscriptions() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('after analysis, no such file', () {
|
||||
AnalysisTestHelper helper = new AnalysisTestHelper();
|
||||
helper.createSingleFileProject('int V = 42;');
|
||||
return helper.waitForOperationsFinished().then((_) {
|
||||
String noFile = '/no-such.file.dart';
|
||||
helper.addAnalysisSubscriptionErrors(noFile);
|
||||
return helper.waitForOperationsFinished().then((_) {
|
||||
var errors = helper.getErrors(noFile);
|
||||
expect(errors, isEmpty);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -484,6 +497,10 @@ class AnalysisTestHelper {
|
||||
handleSuccessfulRequest(request);
|
||||
}
|
||||
|
||||
void addAnalysisSubscriptionErrors(String file) {
|
||||
addAnalysisSubscription(AnalysisService.ERRORS, file);
|
||||
}
|
||||
|
||||
void addAnalysisSubscriptionHighlights(String file) {
|
||||
addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user