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

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

Issue 2050573003: Issue 26629. Detect cache inconsistency in GetContentTask. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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
Index: pkg/analyzer/lib/src/task/general.dart
diff --git a/pkg/analyzer/lib/src/task/general.dart b/pkg/analyzer/lib/src/task/general.dart
index 38d67dfb7035f1b202a38a9bd890d095ff07516c..6b9b13af55233d6cba28102c9f7b607ab15357da 100644
--- a/pkg/analyzer/lib/src/task/general.dart
+++ b/pkg/analyzer/lib/src/task/general.dart
@@ -4,6 +4,7 @@
library analyzer.src.task.general;
+import 'package:analyzer/src/context/cache.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/task/general.dart';
@@ -33,13 +34,36 @@ class GetContentTask extends SourceBasedAnalysisTask {
@override
internalPerform() {
Source source = getRequiredSource();
+ String content;
+ int modificationTime;
try {
TimestampedData<String> data = context.getContents(source);
- outputs[CONTENT] = data.data;
- outputs[MODIFICATION_TIME] = data.modificationTime;
+ content = data.data;
+ modificationTime = data.modificationTime;
} catch (exception) {
- outputs[CONTENT] = '';
- outputs[MODIFICATION_TIME] = -1;
+ content = '';
+ modificationTime = -1;
+ }
+ outputs[CONTENT] = content;
+ outputs[MODIFICATION_TIME] = modificationTime;
+ _validateModificationTimeConsistency(modificationTime);
+ }
+
+ /**
+ * Validate that the [target] cache entry has the same modification time
+ * as the given. Otherwise throw a new [ModificationTimeMismatchError] and
+ * instruct to invalidate targets content.
+ */
+ void _validateModificationTimeConsistency(int modificationTime) {
+ AnalysisContext context = this.context;
+ if (context is InternalAnalysisContext) {
+ CacheEntry entry = context.getCacheEntry(target);
+ if (entry != null && entry.modificationTime != modificationTime) {
+ entry.modificationTime = modificationTime;
+ entry.setState(CONTENT, CacheState.INVALID);
+ entry.setState(MODIFICATION_TIME, CacheState.INVALID);
+ throw new ModificationTimeMismatchError(target);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698