Throw InconsistentFilesystemException instead of NPE in FileStateValue#create.
This allows bazel to handle concurrent modifications to the filesystem without crashing.
@@ -70,14 +70,13 @@ public abstract class FileStateValue implements HasDigest, SkyValue {
public static final NonexistentFileStateValue NONEXISTENT_FILE_STATE_NODE =
new NonexistentFileStateValue();
- protected FileStateValue() {
- }
+ private FileStateValue() {}
public static FileStateValue create(
RootedPath rootedPath,
FilesystemCalls syscallCache,
@Nullable TimestampGranularityMonitor tsgm)
- throws InconsistentFilesystemException, IOException {
+ throws IOException {
Path path = rootedPath.asPath();
Dirent.Type type = syscallCache.getType(path, Symlinks.NOFOLLOW);
if (type == null) {
@@ -91,20 +90,21 @@ public abstract class FileStateValue implements HasDigest, SkyValue {
case FILE:
case UNKNOWN:
FileStatus stat = syscallCache.statIfFound(path, Symlinks.NOFOLLOW);
- Preconditions.checkNotNull(stat, "File %s found in directory, but stat failed", rootedPath);
+ if (stat == null) {
+ throw new InconsistentFilesystemException(
+ "File " + rootedPath + " found in directory, but stat failed");
+ }
return createWithStatNoFollow(
rootedPath,
FileStatusWithDigestAdapter.adapt(stat),
/*digestWillBeInjected=*/ false,
tsgm);
- default:
- throw new IllegalStateException(type.toString());
}
+ throw new AssertionError(type);
}
- public static FileStateValue create(RootedPath rootedPath,
- @Nullable TimestampGranularityMonitor tsgm) throws InconsistentFilesystemException,
- IOException {
+ public static FileStateValue create(
+ RootedPath rootedPath, @Nullable TimestampGranularityMonitor tsgm) throws IOException {
Path path = rootedPath.asPath();
// Stat, but don't throw an exception for the common case of a nonexistent file. This still
// throws an IOException in case any other IO error is encountered.
@@ -121,7 +121,7 @@ public abstract class FileStateValue implements HasDigest, SkyValue {
FileStatusWithDigest statNoFollow,
boolean digestWillBeInjected,
@Nullable TimestampGranularityMonitor tsgm)
- throws InconsistentFilesystemException, IOException {
+ throws IOException {
Path path = rootedPath.asPath();
if (statNoFollow.isFile()) {
return statNoFollow.isSpecialFile()
@@ -410,8 +410,7 @@ public abstract class FileStateValue implements HasDigest, SkyValue {
private static final BigInteger FINGERPRINT =
new BigInteger(1, "DirectoryFileStateValue".getBytes(UTF_8));
- private DirectoryFileStateValue() {
- }
+ private DirectoryFileStateValue() {}
@Override
public FileStateType getType() {
@@ -501,8 +500,7 @@ public abstract class FileStateValue implements HasDigest, SkyValue {
private static final BigInteger FINGERPRINT =
new BigInteger(1, "NonexistentFileStateValue".getBytes(UTF_8));
- private NonexistentFileStateValue() {
- }
+ private NonexistentFileStateValue() {}
@Override
public FileStateType getType() {
