From 47621360d884a1bcbf6115bfcd19d749d8ddeb1b Mon Sep 17 00:00:00 2001 From: Sara Itani Date: Sun, 11 Oct 2015 08:47:12 -0700 Subject: [PATCH 1/3] #70 Visual Studio crashes when I quit debugging - Fix potential NullReferenceExceptions --- Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs | 6 +++--- Nodejs/Product/Analysis/Analysis/VariableDef.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs b/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs index 7cf38ec99..5b2c6ffbd 100644 --- a/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs +++ b/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs @@ -188,9 +188,9 @@ internal void Analyze(DDG ddg, CancellationToken cancel) { } internal virtual void AnalyzeWorker(DDG ddg, CancellationToken cancel) { - if (Tree != ProjectEntry.Tree) { - // we were enqueued and a new version became available, don't re-analyze against - // the old version. + if (Ast != null && ProjectEntry != null && ProjectEntry.Tree != null && Tree != ProjectEntry.Tree) { + // analysis unit properties are invalid or we were enqueued and a new version became available + // don't re-analyze against the old version. return; } diff --git a/Nodejs/Product/Analysis/Analysis/VariableDef.cs b/Nodejs/Product/Analysis/Analysis/VariableDef.cs index 217227ecc..b50664a08 100644 --- a/Nodejs/Product/Analysis/Analysis/VariableDef.cs +++ b/Nodejs/Product/Analysis/Analysis/VariableDef.cs @@ -180,7 +180,7 @@ protected virtual void ExceedsTypeLimit() { if (type.Value == null) { continue; } - if (analyzer == null && type.Value.DeclaringModule != null) { + if (analyzer == null && type.Value != null && type.Value.DeclaringModule != null) { analyzer = type.Value.DeclaringModule.Analysis.ProjectState; } var str = type.ToString(); From 534468bb644b618a9cc71316178c68052e48ed20 Mon Sep 17 00:00:00 2001 From: Sara Itani Date: Wed, 14 Oct 2015 01:10:11 -0700 Subject: [PATCH 2/3] Added Debug.Assert statements --- Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs b/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs index 5b2c6ffbd..9b5edc061 100644 --- a/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs +++ b/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs @@ -188,7 +188,10 @@ internal void Analyze(DDG ddg, CancellationToken cancel) { } internal virtual void AnalyzeWorker(DDG ddg, CancellationToken cancel) { - if (Ast != null && ProjectEntry != null && ProjectEntry.Tree != null && Tree != ProjectEntry.Tree) { + Debug.Assert(Ast != null, "Ast has unexpected null value"); + Debug.Assert(ProjectEntry != null, "ProjectEntry has unexpected null value"); + + if (Ast != null && ProjectEntry != null && Tree != ProjectEntry.Tree) { // analysis unit properties are invalid or we were enqueued and a new version became available // don't re-analyze against the old version. return; From 2549d61b7d870ba0c643a06eac68c80a615c668c Mon Sep 17 00:00:00 2001 From: Sara Itani Date: Wed, 14 Oct 2015 01:16:31 -0700 Subject: [PATCH 3/3] Don't flow through to rest of codepath with Ast and ProjectEntry are null --- Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs b/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs index 9b5edc061..558882652 100644 --- a/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs +++ b/Nodejs/Product/Analysis/Analysis/Analyzer/AnalysisUnit.cs @@ -180,7 +180,7 @@ internal void Analyze(DDG ddg, CancellationToken cancel) { long endTime = _sw.ElapsedMilliseconds; var thisTime = endTime - startTime; _analysisTime += thisTime; - if (thisTime >= 500 || (_analysisTime / _analysisCount) > 500) { + if (thisTime >= 500 || (_analysisTime / _analysisCount) > 500) { Trace.TraceWarning("Analyzed: {0} {1} ({2} count, {3}ms total, {4}ms mean)", this, thisTime, _analysisCount, _analysisTime, (double)_analysisTime / _analysisCount); } } @@ -191,7 +191,7 @@ internal virtual void AnalyzeWorker(DDG ddg, CancellationToken cancel) { Debug.Assert(Ast != null, "Ast has unexpected null value"); Debug.Assert(ProjectEntry != null, "ProjectEntry has unexpected null value"); - if (Ast != null && ProjectEntry != null && Tree != ProjectEntry.Tree) { + if (Ast == null || ProjectEntry == null || Tree != ProjectEntry.Tree) { // analysis unit properties are invalid or we were enqueued and a new version became available // don't re-analyze against the old version. return;