diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart index 66089672b29..0b66b09c760 100644 --- a/sdk/lib/io/file_impl.dart +++ b/sdk/lib/io/file_impl.dart @@ -439,7 +439,7 @@ class _RandomAccessFileIOSync implements IOSink { Future flush() { if (_isClosed) { - throw StateError("${_file?.path ?? "IOSink"} is closed"); + return done; } if (_isBound) { throw StateError("${_file?.path ?? "IOSink"} is bound to a stream"); diff --git a/tests/standalone/io/file_iosink_test.dart b/tests/standalone/io/file_iosink_test.dart index c4cf4969d32..511697f126f 100644 --- a/tests/standalone/io/file_iosink_test.dart +++ b/tests/standalone/io/file_iosink_test.dart @@ -392,13 +392,8 @@ Future testFlushDuringClose(Directory tmpDir) async { final sink = file.openWrite(); final close = sink.close(); - try { - await sink.flush(); - } on StateError catch (e) { - Expect.contains('flush_during_close is closed', e.message); - } - - await close; + Expect.equals(file, await sink.flush()); + Expect.equals(file, await close); } Future testFailedWrite(Directory tmpDir) async { diff --git a/tests/standalone_2/io/file_iosink_test.dart b/tests/standalone_2/io/file_iosink_test.dart index cb57eb9fa03..2518b8939aa 100644 --- a/tests/standalone_2/io/file_iosink_test.dart +++ b/tests/standalone_2/io/file_iosink_test.dart @@ -394,13 +394,8 @@ Future testFlushDuringClose(Directory tmpDir) async { final sink = file.openWrite(); final close = sink.close(); - try { - await sink.flush(); - } on StateError catch (e) { - Expect.contains('flush_during_close is closed', e.message); - } - - await close; + Expect.equals(file, await sink.flush()); + Expect.equals(file, await close); } Future testFailedWrite(Directory tmpDir) async {