aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-10-20 20:59:44 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-10-23 17:16:03 +0200
commit51de88c017910e77f929bc38d5b1b1c315170443 (patch)
treeab2a18da2845d21686570edb6be05b33da00547e /src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
parent10a6b77e342472e29d168060e06f05a9c7cad66f (diff)
Lazy-initialise rootPath in FileSystem.
Path construction entails calling isFileSystemCaseSensitive at a time when subclasses have not been initialised. This can cause a crash. Solve by deferring init of the path. PiperOrigin-RevId: 172914501
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
index ee4bff1785..75851faa91 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
@@ -119,11 +119,8 @@ public abstract class FileSystem {
}
}
- protected final Path rootPath;
-
- protected FileSystem() {
- this.rootPath = getPathFactory().createRootPath(this);
- }
+ /** Lazy-initialized on first access, always use {@link FileSystem#getRootDirectory} */
+ private Path rootPath;
/** Returns filesystem-specific path factory. */
protected PathFactory getPathFactory() {
@@ -152,13 +149,20 @@ public abstract class FileSystem {
if (!pathName.isAbsolute()) {
throw new IllegalArgumentException(pathName.getPathString() + " (not an absolute path)");
}
- return rootPath.getRelative(pathName);
+ return getRootDirectory().getRelative(pathName);
}
/**
* Returns a path representing the root directory of the current file system.
*/
public final Path getRootDirectory() {
+ if (rootPath == null) {
+ synchronized (this) {
+ if (rootPath == null) {
+ rootPath = getPathFactory().createRootPath(this);
+ }
+ }
+ }
return rootPath;
}
@@ -395,7 +399,9 @@ public abstract class FileSystem {
if (maxLinks-- == 0) {
throw new IOException(naive + " (Too many levels of symbolic links)");
}
- if (linkTarget.isAbsolute()) { dir = rootPath; }
+ if (linkTarget.isAbsolute()) {
+ dir = getRootDirectory();
+ }
for (String name : linkTarget.segments()) {
if (name.equals(".") || name.isEmpty()) {
// no-op