From 89e21180097434e055d4a4640192d6726ee468bd Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Tue, 25 Jun 2019 17:10:12 +0000 Subject: [PATCH] Guard against an NPE in incomplete code (issue 37150) Change-Id: Idd5a0936ccd435c12ac9b4f36151204a2b01127a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107307 Reviewed-by: Konstantin Shcheglov Commit-Queue: Brian Wilkerson --- .../lib/src/services/correction/assist_internal.dart | 3 ++- .../correction/assist/convert_to_for_element_test.dart | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart index b465c698fcef..34dc4bb7deae 100644 --- a/pkg/analysis_server/lib/src/services/correction/assist_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/assist_internal.dart @@ -971,7 +971,8 @@ class AssistProcessor { return; } ConstructorElement element = creation.staticElement; - if (element.name != 'fromIterable' || + if (element == null || + element.name != 'fromIterable' || element.enclosingElement != typeProvider.mapType.element) { _coverageMarker(); return; diff --git a/pkg/analysis_server/test/src/services/correction/assist/convert_to_for_element_test.dart b/pkg/analysis_server/test/src/services/correction/assist/convert_to_for_element_test.dart index 597c353bcc66..0a536802ed02 100644 --- a/pkg/analysis_server/test/src/services/correction/assist/convert_to_for_element_test.dart +++ b/pkg/analysis_server/test/src/services/correction/assist/convert_to_for_element_test.dart @@ -187,4 +187,14 @@ f(Iterable i) { } '''); } + + test_undefinedConstructor() async { + verifyNoTestUnitErrors = false; + await resolveTestUnit(''' +f() { + return new Unde/*caret*/fined(); +} +'''); + await assertNoAssist(); + } }