Program: 110815
Project: 110815
Buggy source:
/** 
 * Fetch the skylark loads for this BUILD file. If any of them haven't been computed yet, returns null.
 */
@Nullable static SkylarkImportResult fetchImportsFromBuildFile(Path buildFilePath,PackageIdentifier packageId,BuildFileAST buildFileAST,Environment env,SkylarkImportLookupFunction skylarkImportLookupFunctionForInlining) throws PackageFunctionException, InterruptedException {
  Preconditions.checkArgument(!packageId.getRepository().isDefault());
  ImmutableList<SkylarkImport> imports=buildFileAST.getImports();
  Map<String,Extension> importMap=Maps.newHashMapWithExpectedSize(imports.size());
  ImmutableList.Builder<SkylarkFileDependency> fileDependencies=ImmutableList.builder();
  ImmutableMap<String,Label> importPathMap;
  Label labelForCurrBuildFile;
  try {
    labelForCurrBuildFile=Label.create(packageId,"String_Node_Str");
  }
 catch (  LabelSyntaxException e) {
    throw new IllegalStateException(e);
  }
  try {
    importPathMap=SkylarkImportLookupFunction.findLabelsForLoadStatements(imports,labelForCurrBuildFile,env);
    if (importPathMap == null) {
      return null;
    }
  }
 catch (  SkylarkImportFailedException e) {
    throw new PackageFunctionException(new BuildFileContainsErrorsException(packageId,e.getMessage()),Transience.PERSISTENT);
  }
  ImmutableCollection<Label> importLabels=importPathMap.values();
  List<SkyKey> importLookupKeys=Lists.newArrayListWithExpectedSize(importLabels.size());
  boolean inWorkspace=buildFilePath.getBaseName().endsWith("String_Node_Str");
  for (  Label importLabel : importLabels) {
    importLookupKeys.add(SkylarkImportLookupValue.key(importLabel,inWorkspace));
  }
  Map<SkyKey,SkyValue> skylarkImportMap=Maps.newHashMapWithExpectedSize(importPathMap.size());
  boolean valuesMissing=false;
  try {
    if (skylarkImportLookupFunctionForInlining == null) {
      Map<SkyKey,ValueOrException2<SkylarkImportFailedException,InconsistentFilesystemException>> skylarkLookupResults=env.getValuesOrThrow(importLookupKeys,SkylarkImportFailedException.class,InconsistentFilesystemException.class);
      valuesMissing=env.valuesMissing();
      for (      Map.Entry<SkyKey,ValueOrException2<SkylarkImportFailedException,InconsistentFilesystemException>> entry : skylarkLookupResults.entrySet()) {
        skylarkImportMap.put(entry.getKey(),entry.getValue().get());
      }
    }
 else {
      LinkedHashMap<Label,SkylarkImportLookupValue> alreadyVisitedImports=Maps.newLinkedHashMapWithExpectedSize(importLookupKeys.size());
      for (      SkyKey importLookupKey : importLookupKeys) {
        SkyValue skyValue=skylarkImportLookupFunctionForInlining.computeWithInlineCalls(importLookupKey,env,alreadyVisitedImports);
        if (skyValue == null) {
          Preconditions.checkState(env.valuesMissing(),"String_Node_Str",importLookupKey);
          valuesMissing=true;
        }
 else {
          skylarkImportMap.put(importLookupKey,skyValue);
        }
      }
    }
  }
 catch (  SkylarkImportFailedException e) {
    throw new PackageFunctionException(new BuildFileContainsErrorsException(packageId,e.getMessage()),Transience.PERSISTENT);
  }
catch (  InconsistentFilesystemException e) {
    throw new PackageFunctionException(new NoSuchPackageException(packageId,e.getMessage(),e),Transience.PERSISTENT);
  }
  if (valuesMissing) {
    return null;
  }
  for (  Entry<String,Label> importEntry : importPathMap.entrySet()) {
    String importString=importEntry.getKey();
    Label importLabel=importEntry.getValue();
    SkyKey keyForLabel=SkylarkImportLookupValue.key(importLabel,inWorkspace);
    SkylarkImportLookupValue importLookupValue=(SkylarkImportLookupValue)skylarkImportMap.get(keyForLabel);
    importMap.put(importString,importLookupValue.getEnvironmentExtension());
    fileDependencies.add(importLookupValue.getDependency());
  }
  return new SkylarkImportResult(importMap,transitiveClosureOfLabels(fileDependencies.build()));
}

Fixed version (ground truth):
/** 
 * Fetch the skylark loads for this BUILD file. If any of them haven't been computed yet, returns null.
 */
@Nullable static SkylarkImportResult fetchImportsFromBuildFile(Path buildFilePath,PackageIdentifier packageId,BuildFileAST buildFileAST,Environment env,SkylarkImportLookupFunction skylarkImportLookupFunctionForInlining) throws NoSuchPackageException, InterruptedException {
  Preconditions.checkArgument(!packageId.getRepository().isDefault());
  ImmutableList<SkylarkImport> imports=buildFileAST.getImports();
  Map<String,Extension> importMap=Maps.newHashMapWithExpectedSize(imports.size());
  ImmutableList.Builder<SkylarkFileDependency> fileDependencies=ImmutableList.builder();
  ImmutableMap<String,Label> importPathMap;
  Label labelForCurrBuildFile;
  try {
    labelForCurrBuildFile=Label.create(packageId,"String_Node_Str");
  }
 catch (  LabelSyntaxException e) {
    throw new IllegalStateException(e);
  }
  try {
    importPathMap=SkylarkImportLookupFunction.findLabelsForLoadStatements(imports,labelForCurrBuildFile,env);
    if (importPathMap == null) {
      return null;
    }
  }
 catch (  SkylarkImportFailedException e) {
    throw new BuildFileContainsErrorsException(packageId,e.getMessage());
  }
  ImmutableCollection<Label> importLabels=importPathMap.values();
  List<SkyKey> importLookupKeys=Lists.newArrayListWithExpectedSize(importLabels.size());
  boolean inWorkspace=buildFilePath.getBaseName().endsWith("String_Node_Str");
  for (  Label importLabel : importLabels) {
    importLookupKeys.add(SkylarkImportLookupValue.key(importLabel,inWorkspace));
  }
  Map<SkyKey,SkyValue> skylarkImportMap=Maps.newHashMapWithExpectedSize(importPathMap.size());
  boolean valuesMissing=false;
  try {
    if (skylarkImportLookupFunctionForInlining == null) {
      Map<SkyKey,ValueOrException2<SkylarkImportFailedException,InconsistentFilesystemException>> skylarkLookupResults=env.getValuesOrThrow(importLookupKeys,SkylarkImportFailedException.class,InconsistentFilesystemException.class);
      valuesMissing=env.valuesMissing();
      for (      Map.Entry<SkyKey,ValueOrException2<SkylarkImportFailedException,InconsistentFilesystemException>> entry : skylarkLookupResults.entrySet()) {
        skylarkImportMap.put(entry.getKey(),entry.getValue().get());
      }
    }
 else {
      LinkedHashMap<Label,SkylarkImportLookupValue> alreadyVisitedImports=Maps.newLinkedHashMapWithExpectedSize(importLookupKeys.size());
      for (      SkyKey importLookupKey : importLookupKeys) {
        SkyValue skyValue=skylarkImportLookupFunctionForInlining.computeWithInlineCalls(importLookupKey,env,alreadyVisitedImports);
        if (skyValue == null) {
          Preconditions.checkState(env.valuesMissing(),"String_Node_Str",importLookupKey);
          valuesMissing=true;
        }
 else {
          skylarkImportMap.put(importLookupKey,skyValue);
        }
      }
    }
  }
 catch (  SkylarkImportFailedException e) {
    throw new BuildFileContainsErrorsException(packageId,e.getMessage());
  }
catch (  InconsistentFilesystemException e) {
    throw new NoSuchPackageException(packageId,e.getMessage(),e);
  }
  if (valuesMissing) {
    return null;
  }
  for (  Entry<String,Label> importEntry : importPathMap.entrySet()) {
    String importString=importEntry.getKey();
    Label importLabel=importEntry.getValue();
    SkyKey keyForLabel=SkylarkImportLookupValue.key(importLabel,inWorkspace);
    SkylarkImportLookupValue importLookupValue=(SkylarkImportLookupValue)skylarkImportMap.get(keyForLabel);
    importMap.put(importString,importLookupValue.getEnvironmentExtension());
    fileDependencies.add(importLookupValue.getDependency());
  }
  return new SkylarkImportResult(importMap,transitiveClosureOfLabels(fileDependencies.build()));
}