[dart:io] Provide epoch timestamps in the FileStat notFound object.
This is a breaking change. https://github.com/dart-lang/sdk/issues/40706
The dummy object returned if FileStat.stat() and FileStat.statSync()
fail now contains Unix epoch timestamps instead of null for the
accessed, changed, and modified getters.
These timestamps are always non-null if the API succeeds and the
timestamps are meaningless when the API fails and returns the
FileSystemEntityType.notFound type. This change makes the timestamps
always non-null, which avoids all legitimate accesses needing a needless
null check when Dart becomes null safe. This change is consistent with
the mode and size getters that are initialized to non-null dummy values
when the API fail.
The NNBD migration required making subtle changes to some dart:io
semantics in order to provide a better API. This change backports one of
these semantic changes to the unmigrated SDK so any issues can be
discovered now instead of blocking the future SDK unfork.
Change-Id: Iff6b34d04b60f4c9f4cf8d9dd0679f721d142ba4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136585
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d75ed3..75956c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,11 @@
`ProcessStartMode.inheritStdio`) upon accessing the `stdin`, `stdout`, and
`stderr` getters. Previously these getters would all return `null`.
+* **Breaking change** [#40706](https://github.com/dart-lang/sdk/issues/40706):
+ The dummy object returned if `FileStat.stat()` and `FileStat.statSync()` fail
+ now contains Unix epoch timestamps instead of `null` for the `accessed`,
+ `changed`, and `modified` getters.
+
#### `dart:mirrors`
* Added `MirrorSystem.neverType`.
diff --git a/sdk/lib/io/file_system_entity.dart b/sdk/lib/io/file_system_entity.dart
index 496ecba..3f45ca5 100644
--- a/sdk/lib/io/file_system_entity.dart
+++ b/sdk/lib/io/file_system_entity.dart
@@ -59,7 +59,9 @@
static const _mode = 4;
static const _size = 5;
- static const _notFound = const FileStat._internalNotFound();
+ static final _epoch = DateTime.fromMillisecondsSinceEpoch(0, isUtc: true);
+ static final _notFound = new FileStat._internal(
+ _epoch, _epoch, _epoch, FileSystemEntityType.notFound, 0, -1);
/**
* The time of the last change to the data or metadata of the file system
@@ -105,14 +107,6 @@
FileStat._internal(this.changed, this.modified, this.accessed, this.type,
this.mode, this.size);
- const FileStat._internalNotFound()
- : changed = null,
- modified = null,
- accessed = null,
- type = FileSystemEntityType.notFound,
- mode = 0,
- size = -1;
-
external static _statSync(_Namespace namespace, String path);
/**