Program: 53150
Project: 53150
Buggy source:
/** 
 * @param buildId an identifier for this command execution.
 * @param context an optional NGContext that is present if running inside a Nailgun server.
 * @param args command line arguments
 * @return an exit code or {@code null} if this is a process that should not exit
 */
@SuppressWarnings("String_Node_Str") public int runMainWithExitCode(BuildId buildId,Path projectRoot,Optional<NGContext> context,ImmutableMap<String,String> clientEnvironment,String... args) throws IOException, InterruptedException {
  Verbosity verbosity=VerbosityParser.parse(args);
  Optional<String> color;
  if (context.isPresent() && (context.get().getEnv() != null)) {
    String colorString=context.get().getEnv().getProperty(BUCKD_COLOR_DEFAULT_ENV_VAR);
    color=Optional.fromNullable(colorString);
  }
 else {
    color=Optional.absent();
  }
  BuckCommand command=new BuckCommand();
  AdditionalOptionsCmdLineParser cmdLineParser=new AdditionalOptionsCmdLineParser(command);
  try {
    cmdLineParser.parseArgument(args);
  }
 catch (  CmdLineException e) {
    stdErr.println(e.getLocalizedMessage());
    return 1;
  }
  ImmutableMap<String,ImmutableMap<String,String>> configOverrides=command.getConfigOverrides();
  Path canonicalRootPath=projectRoot.toRealPath().normalize();
  Config rawConfig=Config.createDefaultConfig(canonicalRootPath,configOverrides);
  ProjectFilesystem filesystem=new ProjectFilesystem(canonicalRootPath,rawConfig);
  BuckConfig buckConfig=new BuckConfig(rawConfig,filesystem,architecture,platform,clientEnvironment);
  final Console console=new Console(verbosity,stdOut,stdErr,buckConfig.createAnsi(color));
  boolean commandSemaphoreAcquired=false;
  if (!command.isReadOnly()) {
    commandSemaphoreAcquired=commandSemaphore.tryAcquire();
    if (!commandSemaphoreAcquired) {
      return BUSY_EXIT_CODE;
    }
  }
  PropertyFinder propertyFinder=new DefaultPropertyFinder(filesystem,clientEnvironment);
  AndroidBuckConfig androidBuckConfig=new AndroidBuckConfig(buckConfig,platform);
  AndroidDirectoryResolver androidDirectoryResolver=new DefaultAndroidDirectoryResolver(filesystem,androidBuckConfig.getNdkVersion(),propertyFinder);
  ProcessExecutor processExecutor=new ProcessExecutor(console);
  Optional<Path> testTempDirOverride=getTestTempDirOverride(buckConfig,clientEnvironment,"String_Node_Str" + buildId.toString());
  if (testTempDirOverride.isPresent()) {
    LOG.debug("String_Node_Str",testTempDirOverride.get());
  }
  Clock clock;
  if (BUCKD_LAUNCH_TIME_NANOS.isPresent()) {
    long nanosEpoch=Long.parseLong(BUCKD_LAUNCH_TIME_NANOS.get(),10);
    LOG.verbose("String_Node_Str",nanosEpoch);
    clock=new NanosAdjustedClock(nanosEpoch);
  }
 else {
    clock=new DefaultClock();
  }
  ParserConfig parserConfig=new ParserConfig(buckConfig);
  Watchman watchman;
  ParserConfig.GlobHandler globHandler;
  if (context.isPresent() || parserConfig.getGlobHandler() == ParserConfig.GlobHandler.WATCHMAN) {
    watchman=Watchman.build(projectRoot,clientEnvironment,console,clock);
    if (parserConfig.getGlobHandler() == ParserConfig.GlobHandler.WATCHMAN && watchman.hasWildmatchGlob()) {
      globHandler=ParserConfig.GlobHandler.WATCHMAN;
    }
 else {
      globHandler=ParserConfig.GlobHandler.PYTHON;
    }
    LOG.debug("String_Node_Str" + "String_Node_Str",watchman.getCapabilities(),watchman.getWatchRoot(),watchman.getProjectPrefix(),parserConfig.getGlobHandler(),globHandler);
  }
 else {
    watchman=Watchman.NULL_WATCHMAN;
    globHandler=ParserConfig.GlobHandler.PYTHON;
  }
  final boolean isDaemon=context.isPresent() && (watchman != Watchman.NULL_WATCHMAN);
  KnownBuildRuleTypesFactory factory=new KnownBuildRuleTypesFactory(processExecutor,androidDirectoryResolver,testTempDirOverride);
  Cell rootCell=new Cell(filesystem,console,watchman,buckConfig,factory,androidDirectoryResolver,clock);
  int exitCode;
  ImmutableList<BuckEventListener> eventListeners=ImmutableList.of();
  ExecutionEnvironment executionEnvironment=new DefaultExecutionEnvironment(processExecutor,clientEnvironment,System.getProperties());
  ParserConfig.AllowSymlinks allowSymlinks=parserConfig.getAllowSymlinks();
  ProjectFileHashCache cellHashCache;
  ProjectFileHashCache buckOutHashCache;
  if (isDaemon) {
    cellHashCache=getFileHashCacheFromDaemon(rootCell,globHandler,allowSymlinks);
    buckOutHashCache=getBuckOutFileHashCacheFromDaemon(rootCell,globHandler,allowSymlinks);
  }
 else {
    cellHashCache=new DefaultFileHashCache(rootCell.getFilesystem());
    buckOutHashCache=new DefaultFileHashCache(new ProjectFilesystem(rootCell.getFilesystem().getRootPath(),Optional.of(ImmutableSet.of(BuckConstant.BUCK_OUTPUT_PATH)),ImmutableSet.<Path>of()));
  }
  FileHashCache fileHashCache=new StackedFileHashCache(ImmutableList.of(cellHashCache,buckOutHashCache,new DefaultFileHashCache(new ProjectFilesystem(rootCell.getFilesystem().getRootPath())),new DefaultFileHashCache(new ProjectFilesystem(Paths.get("String_Node_Str")))));
  Optional<WebServer> webServer=getWebServerIfDaemon(context,rootCell,globHandler,allowSymlinks);
  TestConfig testConfig=new TestConfig(buckConfig);
  ArtifactCacheBuckConfig cacheBuckConfig=new ArtifactCacheBuckConfig(buckConfig);
  ExecutorService diskIoExecutorService=MoreExecutors.newSingleThreadExecutor("String_Node_Str");
  VersionControlStatsGenerator vcStatsGenerator=null;
  try (ConsoleLogLevelOverrider consoleLogLevelOverrider=new ConsoleLogLevelOverrider(buildId.toString(),verbosity);ConsoleHandlerRedirector consoleHandlerRedirector=new ConsoleHandlerRedirector(buildId.toString(),console.getStdErr(),Optional.<OutputStream>of(stdErr));AbstractConsoleEventBusListener consoleListener=createConsoleEventListener(clock,console,testConfig.getResultSummaryVerbosity(),executionEnvironment,webServer);TempDirectoryCreator tempDirectoryCreator=new TempDirectoryCreator(testTempDirOverride);AsyncCloseable asyncCloseable=new AsyncCloseable(diskIoExecutorService);BuckEventBus buildEventBus=new BuckEventBus(clock,buildId)){
    ArtifactCache artifactCache=asyncCloseable.closeAsync(ArtifactCaches.newInstance(cacheBuckConfig,buildEventBus,filesystem,executionEnvironment.getWifiSsid()));
    ProgressEstimator progressEstimator=new ProgressEstimator(filesystem.getRootPath(),buildEventBus);
    consoleListener.setProgressEstimator(progressEstimator);
    eventListeners=addEventListeners(buildEventBus,rootCell.getFilesystem(),buildId,rootCell.getBuckConfig(),webServer,clock,executionEnvironment,console,consoleListener,rootCell.getKnownBuildRuleTypes(),clientEnvironment);
    VersionControlBuckConfig vcBuckConfig=new VersionControlBuckConfig(buckConfig);
    if (vcBuckConfig.shouldGenerateStatistics()) {
      vcStatsGenerator=new VersionControlStatsGenerator(diskIoExecutorService,new DefaultVersionControlCmdLineInterfaceFactory(rootCell.getFilesystem().getRootPath(),processExecutor,vcBuckConfig),buildEventBus);
      vcStatsGenerator.generateStatsAsync();
    }
    ImmutableList<String> remainingArgs=args.length > 1 ? ImmutableList.copyOf(Arrays.copyOfRange(args,1,args.length)) : ImmutableList.<String>of();
    CommandEvent.Started startedEvent=CommandEvent.started(args.length > 0 ? args[0] : "String_Node_Str",remainingArgs,isDaemon);
    buildEventBus.post(startedEvent);
    Parser parser=null;
    if (isDaemon && watchman != Watchman.NULL_WATCHMAN) {
      try {
        Daemon daemon=getDaemon(rootCell,globHandler,allowSymlinks,objectMapper);
        WatchmanWatcher watchmanWatcher=new WatchmanWatcher(watchman.getWatchRoot().or(canonicalRootPath.toString()),daemon.getFileEventBus(),clock,objectMapper,processExecutor,filesystem.getIgnorePaths(),DEFAULT_IGNORE_GLOBS,watchman,daemon.getWatchmanQueryUUID());
        parser=getParserFromDaemon(context,rootCell,startedEvent,buildEventBus,watchmanWatcher,globHandler,allowSymlinks);
      }
 catch (      WatchmanWatcherException|IOException e) {
        buildEventBus.post(ConsoleEvent.warning("String_Node_Str",e.getMessage()));
      }
    }
    if (parser == null) {
      parser=Parser.createBuildFileParser(rootCell,globHandler == ParserConfig.GlobHandler.WATCHMAN,allowSymlinks);
    }
    JavaUtilsLoggingBuildListener.ensureLogFileIsWritten(rootCell.getFilesystem());
    Optional<ProcessManager> processManager;
    if (platform == Platform.WINDOWS) {
      processManager=Optional.absent();
    }
 else {
      processManager=Optional.<ProcessManager>of(new PkillProcessManager(processExecutor));
    }
    Supplier<AndroidPlatformTarget> androidPlatformTargetSupplier=createAndroidPlatformTargetSupplier(androidDirectoryResolver,androidBuckConfig,buildEventBus);
    if (command.subcommand instanceof AbstractCommand) {
      AbstractCommand subcommand=(AbstractCommand)command.subcommand;
      Optional<Path> eventsOutputPath=subcommand.getEventsOutputPath();
      if (eventsOutputPath.isPresent()) {
        BuckEventListener listener=new FileSerializationEventBusListener(eventsOutputPath.get());
        buildEventBus.register(listener);
      }
    }
    exitCode=command.run(new CommandRunnerParams(console,rootCell,androidPlatformTargetSupplier,artifactCache,buildEventBus,parser,platform,clientEnvironment,rootCell.getBuckConfig().createDefaultJavaPackageFinder(),objectMapper,clock,processManager,webServer,buckConfig,fileHashCache));
    parser.cleanCache();
    buildEventBus.post(CommandEvent.finished(startedEvent,exitCode));
  }
 catch (  Throwable t) {
    LOG.debug(t,"String_Node_Str");
    closeDiskIoExecutorService(diskIoExecutorService);
    flushEventListeners(console,buildId,eventListeners);
    throw t;
  }
 finally {
    if (commandSemaphoreAcquired) {
      commandSemaphore.release();
    }
  }
  if (context.isPresent() && !rootCell.getBuckConfig().getFlushEventsBeforeExit()) {
    context.get().in.close();
    context.get().exit(exitCode);
  }
  closeDiskIoExecutorService(diskIoExecutorService);
  flushEventListeners(console,buildId,eventListeners);
  return exitCode;
}

Fixed version (ground truth):
/** 
 * @param buildId an identifier for this command execution.
 * @param context an optional NGContext that is present if running inside a Nailgun server.
 * @param args command line arguments
 * @return an exit code or {@code null} if this is a process that should not exit
 */
@SuppressWarnings("String_Node_Str") public int runMainWithExitCode(BuildId buildId,Path projectRoot,Optional<NGContext> context,ImmutableMap<String,String> clientEnvironment,String... args) throws IOException, InterruptedException {
  Verbosity verbosity=VerbosityParser.parse(args);
  Optional<String> color;
  if (context.isPresent() && (context.get().getEnv() != null)) {
    String colorString=context.get().getEnv().getProperty(BUCKD_COLOR_DEFAULT_ENV_VAR);
    color=Optional.fromNullable(colorString);
  }
 else {
    color=Optional.absent();
  }
  BuckCommand command=new BuckCommand();
  AdditionalOptionsCmdLineParser cmdLineParser=new AdditionalOptionsCmdLineParser(command);
  try {
    cmdLineParser.parseArgument(args);
  }
 catch (  CmdLineException e) {
    stdErr.println(e.getLocalizedMessage());
    return 1;
  }
  ImmutableMap<String,ImmutableMap<String,String>> configOverrides=command.getConfigOverrides();
  Path canonicalRootPath=projectRoot.toRealPath().normalize();
  Config rawConfig=Config.createDefaultConfig(canonicalRootPath,configOverrides);
  ProjectFilesystem filesystem=new ProjectFilesystem(canonicalRootPath,rawConfig);
  BuckConfig buckConfig=new BuckConfig(rawConfig,filesystem,architecture,platform,clientEnvironment);
  final Console console=new Console(verbosity,stdOut,stdErr,buckConfig.createAnsi(color));
  boolean commandSemaphoreAcquired=false;
  if (!command.isReadOnly()) {
    commandSemaphoreAcquired=commandSemaphore.tryAcquire();
    if (!commandSemaphoreAcquired) {
      return BUSY_EXIT_CODE;
    }
  }
  PropertyFinder propertyFinder=new DefaultPropertyFinder(filesystem,clientEnvironment);
  AndroidBuckConfig androidBuckConfig=new AndroidBuckConfig(buckConfig,platform);
  AndroidDirectoryResolver androidDirectoryResolver=new DefaultAndroidDirectoryResolver(filesystem,androidBuckConfig.getNdkVersion(),propertyFinder);
  ProcessExecutor processExecutor=new ProcessExecutor(console);
  Optional<Path> testTempDirOverride=getTestTempDirOverride(buckConfig,clientEnvironment,"String_Node_Str" + buildId.toString());
  if (testTempDirOverride.isPresent()) {
    LOG.debug("String_Node_Str",testTempDirOverride.get());
  }
  Clock clock;
  if (BUCKD_LAUNCH_TIME_NANOS.isPresent()) {
    long nanosEpoch=Long.parseLong(BUCKD_LAUNCH_TIME_NANOS.get(),10);
    LOG.verbose("String_Node_Str",nanosEpoch);
    clock=new NanosAdjustedClock(nanosEpoch);
  }
 else {
    clock=new DefaultClock();
  }
  ParserConfig parserConfig=new ParserConfig(buckConfig);
  Watchman watchman;
  ParserConfig.GlobHandler globHandler;
  if (context.isPresent() || parserConfig.getGlobHandler() == ParserConfig.GlobHandler.WATCHMAN) {
    watchman=Watchman.build(projectRoot,clientEnvironment,console,clock);
    if (parserConfig.getGlobHandler() == ParserConfig.GlobHandler.WATCHMAN && watchman.hasWildmatchGlob()) {
      globHandler=ParserConfig.GlobHandler.WATCHMAN;
    }
 else {
      globHandler=ParserConfig.GlobHandler.PYTHON;
    }
    LOG.debug("String_Node_Str" + "String_Node_Str",watchman.getCapabilities(),watchman.getWatchRoot(),watchman.getProjectPrefix(),parserConfig.getGlobHandler(),globHandler);
  }
 else {
    watchman=Watchman.NULL_WATCHMAN;
    globHandler=ParserConfig.GlobHandler.PYTHON;
  }
  final boolean isDaemon=context.isPresent() && (watchman != Watchman.NULL_WATCHMAN);
  KnownBuildRuleTypesFactory factory=new KnownBuildRuleTypesFactory(processExecutor,androidDirectoryResolver,testTempDirOverride);
  Cell rootCell=new Cell(filesystem,console,watchman,buckConfig,factory,androidDirectoryResolver,clock);
  int exitCode;
  ImmutableList<BuckEventListener> eventListeners=ImmutableList.of();
  ExecutionEnvironment executionEnvironment=new DefaultExecutionEnvironment(processExecutor,clientEnvironment,System.getProperties());
  ParserConfig.AllowSymlinks allowSymlinks=parserConfig.getAllowSymlinks();
  ProjectFileHashCache cellHashCache;
  ProjectFileHashCache buckOutHashCache;
  if (isDaemon) {
    cellHashCache=getFileHashCacheFromDaemon(rootCell,globHandler,allowSymlinks);
    buckOutHashCache=getBuckOutFileHashCacheFromDaemon(rootCell,globHandler,allowSymlinks);
  }
 else {
    cellHashCache=new DefaultFileHashCache(rootCell.getFilesystem());
    buckOutHashCache=new DefaultFileHashCache(new ProjectFilesystem(rootCell.getFilesystem().getRootPath(),Optional.of(ImmutableSet.of(BuckConstant.BUCK_OUTPUT_PATH)),ImmutableSet.<Path>of()));
  }
  FileHashCache fileHashCache=new StackedFileHashCache(ImmutableList.of(cellHashCache,buckOutHashCache,new DefaultFileHashCache(new ProjectFilesystem(rootCell.getFilesystem().getRootPath())),new DefaultFileHashCache(new ProjectFilesystem(Paths.get("String_Node_Str")))));
  Optional<WebServer> webServer=getWebServerIfDaemon(context,rootCell,globHandler,allowSymlinks);
  TestConfig testConfig=new TestConfig(buckConfig);
  ArtifactCacheBuckConfig cacheBuckConfig=new ArtifactCacheBuckConfig(buckConfig);
  ExecutorService diskIoExecutorService=MoreExecutors.newSingleThreadExecutor("String_Node_Str");
  VersionControlStatsGenerator vcStatsGenerator=null;
  try (ConsoleLogLevelOverrider consoleLogLevelOverrider=new ConsoleLogLevelOverrider(buildId.toString(),verbosity);ConsoleHandlerRedirector consoleHandlerRedirector=new ConsoleHandlerRedirector(buildId.toString(),console.getStdErr(),Optional.<OutputStream>of(stdErr));AbstractConsoleEventBusListener consoleListener=createConsoleEventListener(clock,console,testConfig.getResultSummaryVerbosity(),executionEnvironment,webServer);TempDirectoryCreator tempDirectoryCreator=new TempDirectoryCreator(testTempDirOverride);AsyncCloseable asyncCloseable=new AsyncCloseable(diskIoExecutorService);BuckEventBus buildEventBus=new BuckEventBus(clock,buildId)){
    ArtifactCache artifactCache=asyncCloseable.closeAsync(ArtifactCaches.newInstance(cacheBuckConfig,buildEventBus,filesystem,executionEnvironment.getWifiSsid()));
    ProgressEstimator progressEstimator=new ProgressEstimator(filesystem.getRootPath(),buildEventBus);
    consoleListener.setProgressEstimator(progressEstimator);
    eventListeners=addEventListeners(buildEventBus,rootCell.getFilesystem(),buildId,rootCell.getBuckConfig(),webServer,clock,executionEnvironment,console,consoleListener,rootCell.getKnownBuildRuleTypes(),clientEnvironment);
    VersionControlBuckConfig vcBuckConfig=new VersionControlBuckConfig(buckConfig);
    if (vcBuckConfig.shouldGenerateStatistics()) {
      vcStatsGenerator=new VersionControlStatsGenerator(diskIoExecutorService,new DefaultVersionControlCmdLineInterfaceFactory(rootCell.getFilesystem().getRootPath(),new PrintStreamProcessExecutorFactory(),vcBuckConfig),buildEventBus);
      vcStatsGenerator.generateStatsAsync();
    }
    ImmutableList<String> remainingArgs=args.length > 1 ? ImmutableList.copyOf(Arrays.copyOfRange(args,1,args.length)) : ImmutableList.<String>of();
    CommandEvent.Started startedEvent=CommandEvent.started(args.length > 0 ? args[0] : "String_Node_Str",remainingArgs,isDaemon);
    buildEventBus.post(startedEvent);
    Parser parser=null;
    if (isDaemon && watchman != Watchman.NULL_WATCHMAN) {
      try {
        Daemon daemon=getDaemon(rootCell,globHandler,allowSymlinks,objectMapper);
        WatchmanWatcher watchmanWatcher=new WatchmanWatcher(watchman.getWatchRoot().or(canonicalRootPath.toString()),daemon.getFileEventBus(),clock,objectMapper,processExecutor,filesystem.getIgnorePaths(),DEFAULT_IGNORE_GLOBS,watchman,daemon.getWatchmanQueryUUID());
        parser=getParserFromDaemon(context,rootCell,startedEvent,buildEventBus,watchmanWatcher,globHandler,allowSymlinks);
      }
 catch (      WatchmanWatcherException|IOException e) {
        buildEventBus.post(ConsoleEvent.warning("String_Node_Str",e.getMessage()));
      }
    }
    if (parser == null) {
      parser=Parser.createBuildFileParser(rootCell,globHandler == ParserConfig.GlobHandler.WATCHMAN,allowSymlinks);
    }
    JavaUtilsLoggingBuildListener.ensureLogFileIsWritten(rootCell.getFilesystem());
    Optional<ProcessManager> processManager;
    if (platform == Platform.WINDOWS) {
      processManager=Optional.absent();
    }
 else {
      processManager=Optional.<ProcessManager>of(new PkillProcessManager(processExecutor));
    }
    Supplier<AndroidPlatformTarget> androidPlatformTargetSupplier=createAndroidPlatformTargetSupplier(androidDirectoryResolver,androidBuckConfig,buildEventBus);
    if (command.subcommand instanceof AbstractCommand) {
      AbstractCommand subcommand=(AbstractCommand)command.subcommand;
      Optional<Path> eventsOutputPath=subcommand.getEventsOutputPath();
      if (eventsOutputPath.isPresent()) {
        BuckEventListener listener=new FileSerializationEventBusListener(eventsOutputPath.get());
        buildEventBus.register(listener);
      }
    }
    exitCode=command.run(new CommandRunnerParams(console,rootCell,androidPlatformTargetSupplier,artifactCache,buildEventBus,parser,platform,clientEnvironment,rootCell.getBuckConfig().createDefaultJavaPackageFinder(),objectMapper,clock,processManager,webServer,buckConfig,fileHashCache));
    parser.cleanCache();
    buildEventBus.post(CommandEvent.finished(startedEvent,exitCode));
  }
 catch (  Throwable t) {
    LOG.debug(t,"String_Node_Str");
    closeDiskIoExecutorService(diskIoExecutorService);
    flushEventListeners(console,buildId,eventListeners);
    throw t;
  }
 finally {
    if (commandSemaphoreAcquired) {
      commandSemaphore.release();
    }
  }
  if (context.isPresent() && !rootCell.getBuckConfig().getFlushEventsBeforeExit()) {
    context.get().in.close();
    context.get().exit(exitCode);
  }
  closeDiskIoExecutorService(diskIoExecutorService);
  flushEventListeners(console,buildId,eventListeners);
  return exitCode;
}