Logical rollforward of https://github.com/bazelbuild/bazel/commit/e2e235359ccdc4b6a122586b9d7c99abbddd65f5. That commit was reverted because it tickled an unrelated bug accidentally exercised by a Google-internal test.

The unrelated bug has been fixed separately.

RELNOTES: None
PiperOrigin-RevId: 234620238
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java
index 0f0aaa6..6f02026 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/FileFunction.java
@@ -117,17 +117,6 @@
     RootedPath realRootedPath = rootedPathFromAncestors;
     FileStateValue realFileStateValue = fileStateValueFromAncestors;
 
-    FileStateValue fileStateValue;
-    if (rootedPath.equals(realRootedPath)) {
-      fileStateValue = Preconditions.checkNotNull(realFileStateValue, rootedPath);
-    } else {
-      // TODO(b/123922036): Yep, this is useless & wasted work.
-      fileStateValue = (FileStateValue) env.getValue(FileStateValue.key(rootedPath));
-      if (fileStateValue == null) {
-        return null;
-      }
-    }
-
     while (realFileStateValue.getType().isSymlink()) {
       PartialResolutionResult getSymlinkTargetRootedPathResult =
           getSymlinkTargetRootedPath(
@@ -147,7 +136,7 @@
         ImmutableList.copyOf(logicalChain),
         rootedPath,
         // TODO(b/123922036): This is a bug. Should be 'fileStateValueFromAncestors'.
-        fileStateValue,
+        fileStateValueFromAncestors,
         realRootedPath,
         realFileStateValue);
   }