Program: 110931
Project: 110931
Buggy source:
@Override public SkyValue compute(SkyKey skyKey,Environment env) throws GlobFunctionException {
  GlobDescriptor glob=(GlobDescriptor)skyKey.argument();
  PathFragment globSubdir=glob.getSubdir();
  if (!globSubdir.equals(PathFragment.EMPTY_FRAGMENT)) {
    PackageLookupValue globSubdirPkgLookupValue=(PackageLookupValue)env.getValue(PackageLookupValue.key(PackageIdentifier.create(glob.getPackageId().getRepository(),glob.getPackageId().getPackageFragment().getRelative(globSubdir))));
    if (globSubdirPkgLookupValue == null) {
      return null;
    }
    if (globSubdirPkgLookupValue.packageExists()) {
      return GlobValue.EMPTY;
    }
  }
  String pattern=glob.getPattern();
  int slashPos=pattern.indexOf('/');
  String patternHead;
  String patternTail;
  if (slashPos == -1) {
    patternHead=pattern;
    patternTail=null;
  }
 else {
    patternHead=pattern.substring(0,slashPos);
    patternTail=pattern.substring(slashPos + 1);
  }
  NestedSetBuilder<PathFragment> matches=NestedSetBuilder.stableOrder();
  if ("String_Node_Str".equals(patternHead)) {
    if (patternTail == null) {
      if (!glob.excludeDirs()) {
        matches.add(globSubdir);
      }
    }
 else {
      SkyKey globKey=GlobValue.internalKey(glob.getPackageId(),glob.getPackageRoot(),globSubdir,patternTail,glob.excludeDirs());
      GlobValue globValue=(GlobValue)env.getValue(globKey);
      if (globValue == null) {
        return null;
      }
      matches.addTransitive(globValue.getMatches());
    }
  }
  PathFragment dirPathFragment=glob.getPackageId().getPackageFragment().getRelative(globSubdir);
  RootedPath dirRootedPath=RootedPath.toRootedPath(glob.getPackageRoot(),dirPathFragment);
  if (alwaysUseDirListing || containsGlobs(patternHead)) {
    DirectoryListingValue listingValue=(DirectoryListingValue)env.getValue(DirectoryListingValue.key(dirRootedPath));
    if (listingValue == null) {
      return null;
    }
    for (    Dirent dirent : listingValue.getDirents()) {
      Type direntType=dirent.getType();
      String fileName=dirent.getName();
      boolean isDirectory=(direntType == Dirent.Type.DIRECTORY);
      if (!UnixGlob.matches(patternHead,fileName,regexPatternCache)) {
        continue;
      }
      if (direntType == Dirent.Type.SYMLINK) {
        RootedPath symlinkRootedPath=RootedPath.toRootedPath(glob.getPackageRoot(),dirPathFragment.getRelative(fileName));
        FileValue symlinkFileValue=(FileValue)env.getValue(FileValue.key(symlinkRootedPath));
        if (symlinkFileValue == null) {
          continue;
        }
        if (!symlinkFileValue.isSymlink()) {
          throw new GlobFunctionException(new InconsistentFilesystemException("String_Node_Str" + symlinkRootedPath.asPath() + "String_Node_Str"),Transience.TRANSIENT);
        }
        isDirectory=symlinkFileValue.isDirectory();
      }
      String subdirPattern="String_Node_Str".equals(patternHead) ? glob.getPattern() : patternTail;
      addFile(fileName,glob,subdirPattern,patternTail == null,isDirectory,matches,env);
    }
  }
 else {
    String fileName=patternHead;
    RootedPath fileRootedPath=RootedPath.toRootedPath(glob.getPackageRoot(),dirPathFragment.getRelative(fileName));
    FileValue fileValue=(FileValue)env.getValue(FileValue.key(fileRootedPath));
    if (fileValue == null) {
      return null;
    }
    if (fileValue.exists()) {
      addFile(fileName,glob,patternTail,patternTail == null,fileValue.isDirectory(),matches,env);
    }
  }
  if (env.valuesMissing()) {
    return null;
  }
  NestedSet<PathFragment> matchesBuilt=matches.build();
  if (matchesBuilt.isEmpty()) {
    return GlobValue.EMPTY;
  }
  return new GlobValue(matchesBuilt);
}

Fixed version (ground truth):
@Override public SkyValue compute(SkyKey skyKey,Environment env) throws GlobFunctionException {
  GlobDescriptor glob=(GlobDescriptor)skyKey.argument();
  PathFragment globSubdir=glob.getSubdir();
  if (!globSubdir.equals(PathFragment.EMPTY_FRAGMENT)) {
    PackageLookupValue globSubdirPkgLookupValue=(PackageLookupValue)env.getValue(PackageLookupValue.key(PackageIdentifier.create(glob.getPackageId().getRepository(),glob.getPackageId().getPackageFragment().getRelative(globSubdir))));
    if (globSubdirPkgLookupValue == null) {
      return null;
    }
    if (globSubdirPkgLookupValue.packageExists()) {
      return GlobValue.EMPTY;
    }
  }
  String pattern=glob.getPattern();
  int slashPos=pattern.indexOf('/');
  String patternHead;
  String patternTail;
  if (slashPos == -1) {
    patternHead=pattern;
    patternTail=null;
  }
 else {
    patternHead=pattern.substring(0,slashPos);
    patternTail=pattern.substring(slashPos + 1);
  }
  NestedSetBuilder<PathFragment> matches=NestedSetBuilder.stableOrder();
  if ("String_Node_Str".equals(patternHead)) {
    if (patternTail == null) {
      if (!glob.excludeDirs()) {
        matches.add(globSubdir);
      }
    }
 else {
      SkyKey globKey=GlobValue.internalKey(glob.getPackageId(),glob.getPackageRoot(),globSubdir,patternTail,glob.excludeDirs());
      GlobValue globValue=(GlobValue)env.getValue(globKey);
      if (globValue == null) {
        return null;
      }
      matches.addTransitive(globValue.getMatches());
    }
  }
  PathFragment dirPathFragment=glob.getPackageId().getPackageFragment().getRelative(globSubdir);
  RootedPath dirRootedPath=RootedPath.toRootedPath(glob.getPackageRoot(),dirPathFragment);
  if (alwaysUseDirListing || containsGlobs(patternHead)) {
    DirectoryListingValue listingValue=(DirectoryListingValue)env.getValue(DirectoryListingValue.key(dirRootedPath));
    if (listingValue == null) {
      return null;
    }
    for (    Dirent dirent : listingValue.getDirents()) {
      Type direntType=dirent.getType();
      String fileName=dirent.getName();
      boolean isDirectory=(direntType == Dirent.Type.DIRECTORY);
      if (!UnixGlob.matches(patternHead,fileName,regexPatternCache)) {
        continue;
      }
      if (direntType == Dirent.Type.SYMLINK) {
        RootedPath symlinkRootedPath=RootedPath.toRootedPath(glob.getPackageRoot(),dirPathFragment.getRelative(fileName));
        FileValue symlinkFileValue=(FileValue)env.getValue(FileValue.key(symlinkRootedPath));
        if (symlinkFileValue == null) {
          continue;
        }
        if (!symlinkFileValue.isSymlink()) {
          throw new GlobFunctionException(new InconsistentFilesystemException("String_Node_Str" + symlinkRootedPath.asPath() + "String_Node_Str"),Transience.TRANSIENT);
        }
        if (!symlinkFileValue.exists()) {
          continue;
        }
        isDirectory=symlinkFileValue.isDirectory();
      }
      String subdirPattern="String_Node_Str".equals(patternHead) ? glob.getPattern() : patternTail;
      addFile(fileName,glob,subdirPattern,patternTail == null,isDirectory,matches,env);
    }
  }
 else {
    String fileName=patternHead;
    RootedPath fileRootedPath=RootedPath.toRootedPath(glob.getPackageRoot(),dirPathFragment.getRelative(fileName));
    FileValue fileValue=(FileValue)env.getValue(FileValue.key(fileRootedPath));
    if (fileValue == null) {
      return null;
    }
    if (fileValue.exists()) {
      addFile(fileName,glob,patternTail,patternTail == null,fileValue.isDirectory(),matches,env);
    }
  }
  if (env.valuesMissing()) {
    return null;
  }
  NestedSet<PathFragment> matchesBuilt=matches.build();
  if (matchesBuilt.isEmpty()) {
    return GlobValue.EMPTY;
  }
  return new GlobValue(matchesBuilt);
}