Skip to content

Commit

Permalink
Avoid passing a nullable value to Completer<nn-type>.complete
Browse files Browse the repository at this point in the history
This is cleanup work required to start enforcing this with static
analysis, as per #53253.

Real quick this issue is that this code is unsafe:

```dart
void f(Completer<int> c, int? i) {
  Future<int>.value(i); // Ouch!
  c.complete(i);        // Ouch!
}
```

Change-Id: I12c4f0a92a2071fb47759d9626689e00cfa42f8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324763
Reviewed-by: Konstantin Shcheglov <[email protected]>
Auto-Submit: Samuel Rawlins <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
srawlins authored and Commit Queue committed Sep 7, 2023
1 parent 725de4e commit 48a8903
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/analysis_server/test/stress/utilities/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ class RequestData {

/// Return a future that will complete when a response is received.
Future<Response> get respondedTo {
if (_response != null) {
return Future.value(_response);
final response = _response;
if (response != null) {
return Future.value(response);
}
var completer = _responseCompleter ??= Completer<Response>();
return completer.future;
Expand Down

0 comments on commit 48a8903

Please sign in to comment.