Tolerate the situation when a package is absent but the configured target is present: because they are retrieved in a batch, it's possible that the package node was retrieved first and still not done, while the configured target was done when retrieved.

PiperOrigin-RevId: 238455901
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
index a9a3852..741499a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
@@ -697,11 +697,20 @@
                 aliasDepsToRedo.add(dep);
                 continue;
               } else {
-                pkgValue =
-                    Preconditions.checkNotNull(
-                        (PackageValue) packageResult.get(),
-                        "Package should have been loaded during dep resolution: %s",
-                        dep);
+                pkgValue = (PackageValue) packageResult.get();
+                if (pkgValue == null) {
+                  // In a race, the getValuesOrThrow call above may have retrieved the package
+                  // before it was done but the configured target after it was done. However, the
+                  // configured target being done implies that the package is now done, so we can
+                  // retrieve it from the graph.
+                  pkgValue =
+                      Preconditions.checkNotNull(
+                          (PackageValue) env.getValue(packageKey),
+                          "Package should have been loaded during dep resolution: %s (%s %s %s)",
+                          dep,
+                          depValue,
+                          packageResult);
+                }
               }
             } else {
               // We were doing AliasConfiguredTarget mop-up.