Program: 4861
Project: 4861
Buggy source:
/** 
 * Starts the   {@link TwillApplication} for the master services.
 * @return The {@link TwillController} for the application.
 */
private TwillController startTwillApplication(TwillRunnerService twillRunner,ServiceStore serviceStore,TokenSecureStoreRenewer secureStoreRenewer){
  try {
    Path tempPath=Files.createDirectories(Paths.get(cConf.get(Constants.CFG_LOCAL_DATA_DIR),cConf.get(Constants.AppFabric.TEMP_DIR)).toAbsolutePath());
    final Path runDir=Files.createTempDirectory(tempPath,"String_Node_Str");
    try {
      Path logbackFile=saveLogbackConf(runDir.resolve("String_Node_Str"));
      MasterTwillApplication masterTwillApp=new MasterTwillApplication(cConf,getServiceInstances(serviceStore,cConf));
      List<String> extraClassPath=masterTwillApp.prepareLocalizeResource(runDir,hConf);
      TwillPreparer preparer=twillRunner.prepare(masterTwillApp);
      if (!cConf.getBoolean(Constants.COLLECT_CONTAINER_LOGS)) {
        preparer.withConfiguration(Collections.singletonMap(Configs.Keys.LOG_COLLECTION_ENABLED,"String_Node_Str"));
      }
      if (Files.exists(logbackFile)) {
        preparer.withResources(logbackFile.toUri()).withEnv(Collections.singletonMap("String_Node_Str",ApplicationConstants.LOG_DIR_EXPANSION_VAR));
      }
      String queueName=cConf.get(Constants.Service.SCHEDULER_QUEUE);
      if (queueName != null) {
        LOG.info("String_Node_Str",queueName);
        preparer.setSchedulerQueue(queueName);
      }
      preparer.withDependencies(injector.getInstance(HBaseTableUtil.class).getClass());
      Class<? extends HBaseDDLExecutor> ddlExecutorClass=new HBaseDDLExecutorFactory(cConf,hConf).get().getClass();
      preparer.withDependencies(ddlExecutorClass);
      if (User.isHBaseSecurityEnabled(hConf) || UserGroupInformation.isSecurityEnabled()) {
        preparer.addSecureStore(YarnSecureStore.create(secureStoreRenewer.createCredentials()));
      }
      List<String> yarnAppClassPath=Arrays.asList(hConf.getTrimmedStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH,YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
      preparer.withApplicationClassPaths(yarnAppClassPath).withBundlerClassAcceptor(new HadoopClassExcluder());
      boolean yarnFirst=cConf.getBoolean(Constants.Explore.CONTAINER_YARN_APP_CLASSPATH_FIRST);
      if (yarnFirst) {
        preparer=preparer.withClassPaths(Iterables.concat(yarnAppClassPath,extraClassPath));
      }
 else {
        preparer=preparer.withClassPaths(extraClassPath);
      }
      if (cConf.getBoolean(Constants.Explore.EXPLORE_ENABLED)) {
        prepareExploreContainer(preparer);
      }
      preparer.setClassLoader(MainClassLoader.class.getName());
      ClassLoader oldClassLoader=ClassLoaders.setContextClassLoader(new CombineClassLoader(Objects.firstNonNull(Thread.currentThread().getContextClassLoader(),getClass().getClassLoader()),Collections.singleton(ddlExecutorClass.getClassLoader())));
      TwillController controller;
      try {
        controller=preparer.start(cConf.getLong(Constants.AppFabric.PROGRAM_MAX_START_SECONDS),TimeUnit.SECONDS);
      }
  finally {
        ClassLoaders.setContextClassLoader(oldClassLoader);
      }
      Runnable cleanup=new Runnable(){
        @Override public void run(){
          try {
            File dir=runDir.toFile();
            if (dir.isDirectory()) {
              DirUtils.deleteDirectoryContents(dir);
            }
          }
 catch (          IOException e) {
            LOG.warn("String_Node_Str",runDir,e);
          }
        }
      }
;
      controller.onRunning(cleanup,Threads.SAME_THREAD_EXECUTOR);
      controller.onTerminated(cleanup,Threads.SAME_THREAD_EXECUTOR);
      return controller;
    }
 catch (    Exception e) {
      try {
        DirUtils.deleteDirectoryContents(runDir.toFile());
      }
 catch (      IOException ex) {
        LOG.warn("String_Node_Str",runDir,ex);
        e.addSuppressed(ex);
      }
      throw e;
    }
  }
 catch (  IOException e) {
    throw Throwables.propagate(e);
  }
}

Fixed version (ground truth):
/** 
 * Starts the   {@link TwillApplication} for the master services.
 * @return The {@link TwillController} for the application.
 */
private TwillController startTwillApplication(TwillRunnerService twillRunner,ServiceStore serviceStore,TokenSecureStoreRenewer secureStoreRenewer){
  try {
    Path tempPath=Files.createDirectories(Paths.get(cConf.get(Constants.CFG_LOCAL_DATA_DIR),cConf.get(Constants.AppFabric.TEMP_DIR)).toAbsolutePath());
    final Path runDir=Files.createTempDirectory(tempPath,"String_Node_Str");
    try {
      Path logbackFile=saveLogbackConf(runDir.resolve("String_Node_Str"));
      MasterTwillApplication masterTwillApp=new MasterTwillApplication(cConf,getServiceInstances(serviceStore,cConf));
      List<String> extraClassPath=masterTwillApp.prepareLocalizeResource(runDir,hConf);
      TwillPreparer preparer=twillRunner.prepare(masterTwillApp);
      if (!cConf.getBoolean(Constants.COLLECT_CONTAINER_LOGS)) {
        preparer.withConfiguration(Collections.singletonMap(Configs.Keys.LOG_COLLECTION_ENABLED,"String_Node_Str"));
      }
      if (Files.exists(logbackFile)) {
        preparer.withResources(logbackFile.toUri()).withEnv(Collections.singletonMap("String_Node_Str",ApplicationConstants.LOG_DIR_EXPANSION_VAR));
      }
      String queueName=cConf.get(Constants.Service.SCHEDULER_QUEUE);
      if (queueName != null) {
        LOG.info("String_Node_Str",queueName);
        preparer.setSchedulerQueue(queueName);
      }
      preparer.withDependencies(injector.getInstance(HBaseTableUtil.class).getClass());
      if (User.isHBaseSecurityEnabled(hConf) || UserGroupInformation.isSecurityEnabled()) {
        preparer.addSecureStore(YarnSecureStore.create(secureStoreRenewer.createCredentials()));
      }
      List<String> yarnAppClassPath=Arrays.asList(hConf.getTrimmedStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH,YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
      preparer.withApplicationClassPaths(yarnAppClassPath).withBundlerClassAcceptor(new HadoopClassExcluder());
      boolean yarnFirst=cConf.getBoolean(Constants.Explore.CONTAINER_YARN_APP_CLASSPATH_FIRST);
      if (yarnFirst) {
        preparer=preparer.withClassPaths(Iterables.concat(yarnAppClassPath,extraClassPath));
      }
 else {
        preparer=preparer.withClassPaths(extraClassPath);
      }
      if (cConf.getBoolean(Constants.Explore.EXPLORE_ENABLED)) {
        prepareExploreContainer(preparer);
      }
      preparer.setClassLoader(MainClassLoader.class.getName());
      TwillController controller=preparer.start(cConf.getLong(Constants.AppFabric.PROGRAM_MAX_START_SECONDS),TimeUnit.SECONDS);
      Runnable cleanup=new Runnable(){
        @Override public void run(){
          try {
            File dir=runDir.toFile();
            if (dir.isDirectory()) {
              DirUtils.deleteDirectoryContents(dir);
            }
          }
 catch (          IOException e) {
            LOG.warn("String_Node_Str",runDir,e);
          }
        }
      }
;
      controller.onRunning(cleanup,Threads.SAME_THREAD_EXECUTOR);
      controller.onTerminated(cleanup,Threads.SAME_THREAD_EXECUTOR);
      return controller;
    }
 catch (    Exception e) {
      try {
        DirUtils.deleteDirectoryContents(runDir.toFile());
      }
 catch (      IOException ex) {
        LOG.warn("String_Node_Str",runDir,ex);
        e.addSuppressed(ex);
      }
      throw e;
    }
  }
 catch (  IOException e) {
    throw Throwables.propagate(e);
  }
}