Skip to content

Commit 274b4d3

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/nnbd] Avoid passing null as a non-nullable argument of _AssertionError._create
In kernel files assertion conditions are specified as a range of source positions. Sometimes source texts are not available and VM cannot extract assertion condition text, so Script::GetSnippet returns null. With null safety it is no longer valid to pass null as a non-nullable argument '_failedAssertion' of _AssertionError._create constructor, so we should provide a valid String. This change converts 'null' assertion condition text to "<optimized out>", similarly to AOT mode. Issue flutter/flutter#63513 Issue dart-lang/sdk#34586 Change-Id: I9c5791e98fdef358068f3f5ddc4cfe98e8c7ed36 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158162 Reviewed-by: Régis Crelier <regis@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
1 parent eaa9603 commit 274b4d3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

runtime/lib/errors.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ DEFINE_NATIVE_ENTRY(AssertionError_throwNew, 0, 3) {
9090
script.GetTokenLocation(assertion_start, &from_line, &from_column);
9191
intptr_t to_line, to_column;
9292
script.GetTokenLocation(assertion_end, &to_line, &to_column);
93-
// The snippet will extract the correct assertion code even if the source
94-
// is generated.
95-
args.SetAt(0, String::Handle(script.GetSnippet(from_line, from_column,
96-
to_line, to_column)));
93+
// Extract the assertion condition text (if source is available).
94+
auto& condition_text = String::Handle(
95+
script.GetSnippet(from_line, from_column, to_line, to_column));
96+
if (condition_text.IsNull()) {
97+
condition_text = Symbols::OptimizedOut().raw();
98+
}
99+
args.SetAt(0, condition_text);
97100

98101
// Initialize location arguments starting at position 1.
99102
// Do not set a column if the source has been generated as it will be wrong.

0 commit comments

Comments
 (0)