Propagate DefaultHashFunctionNotSetException past the filesystem
We want to discourage users to call getDefault() if they don't absolutely have to.
1) it shouldn't be called in static initialization, since the default will not be set, nor should it be called before initServer() is called for all BlazeModules (the later is less likely to happen, that's pretty early in Bazel startup, but still, one needs to be careful when modifying things that are set early in the Bazel server lifecycle.)
2) Calling it after initialization does not carry the DefaultNotSet risk but it may increase contention, since getDefault is synchronized.
Making the exception explicit at FileSystem initialization should serve as a warning for people to be careful. It also encourages those who can to pass in the known value instead of reading it from global state.
RELNOTES: None.
PiperOrigin-RevId: 209837703
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
index 096ca50..771e073 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
@@ -16,6 +16,7 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
+import com.google.devtools.build.lib.vfs.DigestHashFunction.DefaultHashFunctionNotSetException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -30,7 +31,7 @@
protected static final String ERR_PERMISSION_DENIED = " (Permission denied)";
protected static final Profiler profiler = Profiler.instance();
- public AbstractFileSystem() {}
+ public AbstractFileSystem() throws DefaultHashFunctionNotSetException {}
public AbstractFileSystem(DigestHashFunction digestFunction) {
super(digestFunction);