Program: 12327
Project: 12327
Buggy source:
public boolean installMods(final ServerList server,List<GenericModule> toInstall,List<ConfigFile> configs,boolean clearExisting,final Instance instData,ModSide side) throws FileNotFoundException {
  if (Version.requestedFeatureLevel(server.getMCUVersion(),"String_Node_Str")) {
  }
  final Path instancePath=instanceRoot.resolve(server.getServerId());
  Path binPath=instancePath.resolve("String_Node_Str");
  final Path productionJar;
  final File tmpFolder=instancePath.resolve("String_Node_Str").toFile();
  tmpFolder.mkdirs();
  Set<Downloadable> jarMods=new HashSet<Downloadable>();
  Set<Downloadable> generalFiles=new HashSet<Downloadable>();
  DownloadQueue jarQueue=null;
  DownloadQueue generalQueue=null;
  DownloadQueue libraryQueue=null;
  final List<String> libExtract=new ArrayList<String>();
  final Map<String,Boolean> modExtract=new HashMap<String,Boolean>();
  final Map<String,Boolean> keepMeta=new TreeMap<String,Boolean>();
  Downloadable baseJar=null;
switch (side) {
case CLIENT:
    MinecraftVersion version=MinecraftVersion.loadVersion(server.getVersion());
  Set<Downloadable> libSet=new HashSet<Downloadable>();
for (Library lib : version.getLibraries()) {
  if (lib.validForOS()) {
    List<URL> urls=new ArrayList<URL>();
    try {
      urls.add(new URL(lib.getDownloadUrl()));
    }
 catch (    MalformedURLException e) {
      apiLogger.log(Level.SEVERE,"String_Node_Str",e);
    }
    Downloadable entry=new Downloadable(lib.getName(),lib.getFilename(),"String_Node_Str",100000,urls);
    libSet.add(entry);
    if (lib.hasNatives()) {
      libExtract.add(lib.getFilename());
    }
  }
}
libraryQueue=parent.submitNewQueue("String_Node_Str",server.getServerId(),libSet,instancePath.resolve("String_Node_Str").toFile(),DownloadCache.getDir());
productionJar=binPath.resolve("String_Node_Str");
List<URL> jarUrl=new ArrayList<URL>();
try {
jarUrl.add(new URL("String_Node_Str" + server.getVersion() + "String_Node_Str"+ server.getVersion()+ "String_Node_Str"));
}
 catch (MalformedURLException e2) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e2);
}
String jarMD5="String_Node_Str";
for (Entry<String,String> entry : versionMap.entrySet()) {
if (entry.getValue().equals(server.getVersion())) {
jarMD5=entry.getKey();
break;
}
}
baseJar=new Downloadable("String_Node_Str","String_Node_Str",jarMD5,3000000,jarUrl);
keepMeta.put("String_Node_Str",Version.requestedFeatureLevel(server.getVersion(),"String_Node_Str"));
break;
case SERVER:
productionJar=instancePath.resolve("String_Node_Str");
break;
default :
apiLogger.severe("String_Node_Str" + side.toString() + "String_Node_Str");
return false;
}
Boolean updateJar=clearExisting;
if (side == ModSide.CLIENT) {
if (!productionJar.toFile().exists()) {
updateJar=true;
}
}
 else {
}
Iterator<GenericModule> iMods=toInstall.iterator();
List<String> modIds=new ArrayList<String>();
int jarModCount=0;
while (iMods.hasNext() && !updateJar) {
GenericModule current=iMods.next();
if (current.getInJar()) {
FileInfo jarMod=instData.findJarMod(current.getId());
if (jarMod == null) {
updateJar=true;
}
 else if (current.getMD5().isEmpty() || (!current.getMD5().equalsIgnoreCase(jarMod.getMD5()))) {
updateJar=true;
}
jarModCount++;
}
 else {
modIds.add(current.getId());
}
}
if (jarModCount != instData.getJarMods().size()) {
updateJar=true;
}
if (updateJar && baseJar != null) {
jarMods.add(baseJar);
}
Iterator<FileInfo> itExisting=instData.getInstanceFiles().iterator();
while (itExisting.hasNext()) {
FileInfo entry=itExisting.next();
if (!modIds.contains(entry.getModId())) {
instancePath.resolve(entry.getFilename()).toFile().delete();
}
}
instData.setJarMods(new ArrayList<FileInfo>());
instData.setInstanceFiles(new ArrayList<FileInfo>());
jarModCount=0;
apiLogger.info("String_Node_Str" + instancePath.toString());
List<File> contents=recurseFolder(instancePath.toFile(),true);
if (clearExisting) {
parent.setStatus("String_Node_Str");
parent.log("String_Node_Str");
Iterator<File> it=new ArrayList<File>(contents).iterator();
while (it.hasNext()) {
File entry=it.next();
if (getExcludedNames(entry.getPath(),true)) {
contents.remove(entry);
}
}
ListIterator<File> liClear=contents.listIterator(contents.size());
while (liClear.hasPrevious()) {
File entry=liClear.previous();
entry.delete();
}
}
Iterator<GenericModule> itMods=toInstall.iterator();
final File buildJar=archiveFolder.resolve("String_Node_Str").toFile();
if (buildJar.exists()) {
buildJar.delete();
}
int modCount=toInstall.size();
int modsLoaded=0;
int errorCount=0;
while (itMods.hasNext()) {
GenericModule entry=itMods.next();
parent.setStatus("String_Node_Str" + entry.getName());
parent.log("String_Node_Str" + entry.getName());
Collections.sort(entry.getPrioritizedUrls());
if (entry.getInJar()) {
if (updateJar) {
jarMods.add(new Downloadable(entry.getName(),String.valueOf(entry.getJarOrder()) + "String_Node_Str" + entry.getId()+ "String_Node_Str",entry.getMD5(),100000,entry.getUrls()));
keepMeta.put(String.valueOf(entry.getJarOrder()) + "String_Node_Str" + cleanForFile(entry.getId())+ "String_Node_Str",entry.getKeepMeta());
instData.addJarMod(entry.getId(),entry.getMD5());
jarModCount++;
}
}
 else if (entry.getCoreMod()) {
String filename="String_Node_Str" + cleanForFile(entry.getId()) + "String_Node_Str";
generalFiles.add(new Downloadable(entry.getName(),filename,entry.getMD5(),100000,entry.getUrls()));
instData.addMod(entry.getId(),entry.getMD5(),filename);
}
 else if (entry.getIsLibrary()) {
String filename="String_Node_Str" + cleanForFile(entry.getId()) + "String_Node_Str";
generalFiles.add(new Downloadable(entry.getName(),filename,entry.getMD5(),100000,entry.getUrls()));
instData.addMod(entry.getId(),entry.getMD5(),filename);
}
 else if (entry.getExtract()) {
generalFiles.add(new Downloadable(entry.getName(),cleanForFile(entry.getId()) + "String_Node_Str",entry.getMD5(),100000,entry.getUrls()));
modExtract.put(cleanForFile(entry.getId()) + "String_Node_Str",entry.getInRoot());
}
 else {
String filename=entry.getPath().isEmpty() ? "String_Node_Str" + cleanForFile(entry.getId()) + (entry.isLitemod() ? "String_Node_Str" : "String_Node_Str") : entry.getPath();
generalFiles.add(new Downloadable(entry.getName(),filename,entry.getMD5(),100000,entry.getUrls()));
instData.addMod(entry.getId(),entry.getMD5(),filename);
}
modsLoaded++;
parent.log("String_Node_Str" + modsLoaded + "String_Node_Str"+ modCount+ "String_Node_Str");
}
Iterator<ConfigFile> itConfigs=configs.iterator();
while (itConfigs.hasNext()) {
final ConfigFile cfEntry=itConfigs.next();
final File confFile=instancePath.resolve(cfEntry.getPath()).toFile();
if (confFile.exists() && cfEntry.isNoOverwrite()) {
continue;
}
List<URL> configUrl=new ArrayList<URL>();
try {
configUrl.add(new URL(cfEntry.getUrl()));
}
 catch (MalformedURLException e) {
++errorCount;
apiLogger.log(Level.SEVERE,"String_Node_Str",e);
}
generalFiles.add(new Downloadable(cfEntry.getPath(),cfEntry.getPath(),cfEntry.getMD5(),10000,configUrl));
}
generalQueue=parent.submitNewQueue("String_Node_Str",server.getServerId(),generalFiles,instancePath.toFile(),DownloadCache.getDir());
jarQueue=parent.submitNewQueue("String_Node_Str",server.getServerId(),jarMods,tmpFolder,DownloadCache.getDir());
TaskableExecutor libExecutor=new TaskableExecutor(2,new Runnable(){
@Override public void run(){
for (String entry : libExtract) {
Archive.extractZip(instancePath.resolve("String_Node_Str").resolve(entry).toFile(),instancePath.resolve("String_Node_Str").resolve("String_Node_Str").toFile(),false);
}
}
}
);
libraryQueue.processQueue(libExecutor);
final File branding=new File(tmpFolder,"String_Node_Str");
try {
branding.createNewFile();
Properties propBrand=new Properties();
propBrand.setProperty("String_Node_Str","String_Node_Str" + server.getName() + "String_Node_Str"+ server.getRevision()+ "String_Node_Str");
propBrand.store(new FileOutputStream(branding),"String_Node_Str");
}
 catch (IOException e1) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e1);
}
final boolean doJarUpdate=updateJar;
TaskableExecutor jarExecutor=new TaskableExecutor(2,new Runnable(){
@Override public void run(){
for (Map.Entry<String,Boolean> entry : keepMeta.entrySet()) {
File entryFile=new File(tmpFolder,entry.getKey());
Archive.extractZip(entryFile,tmpFolder,entry.getValue());
entryFile.delete();
}
try {
buildJar.createNewFile();
}
 catch (IOException e) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e);
}
boolean doManifest=true;
List<File> buildList=recurseFolder(tmpFolder,true);
Iterator<File> blIt=new ArrayList<File>(buildList).iterator();
while (blIt.hasNext()) {
File entry=blIt.next();
if (entry.getPath().contains("String_Node_Str")) {
doManifest=false;
}
}
if (!doJarUpdate) {
try {
Archive.updateArchive(productionJar.toFile(),new File[]{branding});
}
 catch (IOException e1) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e1);
}
}
 else {
parent.log("String_Node_Str");
try {
Archive.createJar(buildJar,buildList,tmpFolder.getPath() + sep,doManifest);
}
 catch (IOException e1) {
parent.log("String_Node_Str");
apiLogger.log(Level.SEVERE,"String_Node_Str",e1);
}
try {
Files.copy(new Path(buildJar),productionJar);
}
 catch (IOException e) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e);
}
}
List<File> tempFiles=recurseFolder(tmpFolder,true);
ListIterator<File> li=tempFiles.listIterator(tempFiles.size());
while (li.hasPrevious()) {
File entry=li.previous();
entry.delete();
}
if (server.isGenerateList()) {
writeMCServerFile(server.getName(),server.getAddress(),server.getServerId());
}
instData.setMCVersion(server.getVersion());
instData.setRevision(server.getRevision());
String jsonOut=gson.toJson(instData);
try {
BufferedWriter writer=Files.newBufferedWriter(getInstanceRoot().resolve(server.getServerId()).resolve("String_Node_Str"));
writer.append(jsonOut);
writer.close();
}
 catch (IOException e) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e);
}
}
}
);
jarQueue.processQueue(jarExecutor);
TaskableExecutor genExecutor=new TaskableExecutor(12,new Runnable(){
@Override public void run(){
for (Map.Entry<String,Boolean> entry : modExtract.entrySet()) {
if (entry.getValue()) {
Archive.extractZip(instancePath.resolve(entry.getKey()).toFile(),instancePath.toFile());
}
 else {
Archive.extractZip(instancePath.resolve(entry.getKey()).toFile(),instancePath.resolve("String_Node_Str").toFile());
}
instancePath.resolve(entry.getKey()).toFile().delete();
}
}
}
);
generalQueue.processQueue(genExecutor);
if (errorCount > 0) {
parent.baseLogger.severe("String_Node_Str");
return false;
}
return true;
}

Fixed version (ground truth):
public boolean installMods(final ServerList server,List<GenericModule> toInstall,List<ConfigFile> configs,boolean clearExisting,final Instance instData,ModSide side) throws FileNotFoundException {
  if (Version.requestedFeatureLevel(server.getMCUVersion(),"String_Node_Str")) {
  }
  final Path instancePath=instanceRoot.resolve(server.getServerId());
  Path binPath=instancePath.resolve("String_Node_Str");
  final Path productionJar;
  final File tmpFolder=instancePath.resolve("String_Node_Str").toFile();
  tmpFolder.mkdirs();
  Set<Downloadable> jarMods=new HashSet<Downloadable>();
  Set<Downloadable> generalFiles=new HashSet<Downloadable>();
  DownloadQueue jarQueue=null;
  DownloadQueue generalQueue=null;
  DownloadQueue libraryQueue=null;
  final List<String> libExtract=new ArrayList<String>();
  final Map<String,Boolean> modExtract=new HashMap<String,Boolean>();
  final Map<String,Boolean> keepMeta=new TreeMap<String,Boolean>();
  Downloadable baseJar=null;
switch (side) {
case CLIENT:
    MinecraftVersion version=MinecraftVersion.loadVersion(server.getVersion());
  Set<Downloadable> libSet=new HashSet<Downloadable>();
for (Library lib : version.getLibraries()) {
  if (lib.validForOS()) {
    List<URL> urls=new ArrayList<URL>();
    try {
      urls.add(new URL(lib.getDownloadUrl()));
    }
 catch (    MalformedURLException e) {
      apiLogger.log(Level.SEVERE,"String_Node_Str",e);
    }
    Downloadable entry=new Downloadable(lib.getName(),lib.getFilename(),"String_Node_Str",100000,urls);
    libSet.add(entry);
    if (lib.hasNatives()) {
      libExtract.add(lib.getFilename());
    }
  }
}
libraryQueue=parent.submitNewQueue("String_Node_Str",server.getServerId(),libSet,instancePath.resolve("String_Node_Str").toFile(),DownloadCache.getDir());
productionJar=binPath.resolve("String_Node_Str");
List<URL> jarUrl=new ArrayList<URL>();
try {
jarUrl.add(new URL("String_Node_Str" + server.getVersion() + "String_Node_Str"+ server.getVersion()+ "String_Node_Str"));
}
 catch (MalformedURLException e2) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e2);
}
String jarMD5="String_Node_Str";
for (Entry<String,String> entry : versionMap.entrySet()) {
if (entry.getValue().equals(server.getVersion())) {
jarMD5=entry.getKey();
break;
}
}
baseJar=new Downloadable("String_Node_Str","String_Node_Str",jarMD5,3000000,jarUrl);
keepMeta.put("String_Node_Str",Version.requestedFeatureLevel(server.getVersion(),"String_Node_Str"));
break;
case SERVER:
productionJar=instancePath.resolve("String_Node_Str");
break;
default :
apiLogger.severe("String_Node_Str" + side.toString() + "String_Node_Str");
return false;
}
Boolean updateJar=clearExisting;
if (side == ModSide.CLIENT) {
if (!productionJar.toFile().exists()) {
updateJar=true;
}
}
 else {
}
Iterator<GenericModule> iMods=toInstall.iterator();
List<String> modIds=new ArrayList<String>();
int jarModCount=0;
while (iMods.hasNext() && !updateJar) {
GenericModule current=iMods.next();
if (current.getInJar()) {
FileInfo jarMod=instData.findJarMod(current.getId());
if (jarMod == null) {
updateJar=true;
}
 else if (current.getMD5().isEmpty() || (!current.getMD5().equalsIgnoreCase(jarMod.getMD5()))) {
updateJar=true;
}
jarModCount++;
}
 else {
modIds.add(current.getId());
}
}
if (jarModCount != instData.getJarMods().size()) {
updateJar=true;
}
if (updateJar && baseJar != null) {
jarMods.add(baseJar);
}
Iterator<FileInfo> itExisting=instData.getInstanceFiles().iterator();
while (itExisting.hasNext()) {
FileInfo entry=itExisting.next();
if (!modIds.contains(entry.getModId())) {
instancePath.resolve(entry.getFilename()).toFile().delete();
}
}
instData.setJarMods(new ArrayList<FileInfo>());
instData.setInstanceFiles(new ArrayList<FileInfo>());
jarModCount=0;
apiLogger.info("String_Node_Str" + instancePath.toString());
List<File> contents=recurseFolder(instancePath.toFile(),true);
if (clearExisting) {
parent.setStatus("String_Node_Str");
parent.log("String_Node_Str");
Iterator<File> it=new ArrayList<File>(contents).iterator();
while (it.hasNext()) {
File entry=it.next();
if (getExcludedNames(entry.getPath(),true)) {
contents.remove(entry);
}
}
ListIterator<File> liClear=contents.listIterator(contents.size());
while (liClear.hasPrevious()) {
File entry=liClear.previous();
entry.delete();
}
}
Iterator<GenericModule> itMods=toInstall.iterator();
final File buildJar=archiveFolder.resolve("String_Node_Str").toFile();
if (buildJar.exists()) {
buildJar.delete();
}
int modCount=toInstall.size();
int modsLoaded=0;
int errorCount=0;
while (itMods.hasNext()) {
GenericModule entry=itMods.next();
parent.setStatus("String_Node_Str" + entry.getName());
parent.log("String_Node_Str" + entry.getName());
Collections.sort(entry.getPrioritizedUrls());
if (entry.getInJar()) {
if (updateJar) {
jarMods.add(new Downloadable(entry.getName(),String.valueOf(entry.getJarOrder()) + "String_Node_Str" + entry.getId()+ "String_Node_Str",entry.getMD5(),100000,entry.getUrls()));
keepMeta.put(String.valueOf(entry.getJarOrder()) + "String_Node_Str" + cleanForFile(entry.getId())+ "String_Node_Str",entry.getKeepMeta());
instData.addJarMod(entry.getId(),entry.getMD5());
jarModCount++;
}
}
 else if (entry.getCoreMod()) {
String filename="String_Node_Str" + cleanForFile(entry.getId()) + "String_Node_Str";
generalFiles.add(new Downloadable(entry.getName(),filename,entry.getMD5(),100000,entry.getUrls()));
instData.addMod(entry.getId(),entry.getMD5(),filename);
}
 else if (entry.getIsLibrary()) {
String filename="String_Node_Str" + cleanForFile(entry.getId()) + "String_Node_Str";
generalFiles.add(new Downloadable(entry.getName(),filename,entry.getMD5(),100000,entry.getUrls()));
instData.addMod(entry.getId(),entry.getMD5(),filename);
}
 else if (entry.getExtract()) {
generalFiles.add(new Downloadable(entry.getName(),cleanForFile(entry.getId()) + "String_Node_Str",entry.getMD5(),100000,entry.getUrls()));
modExtract.put(cleanForFile(entry.getId()) + "String_Node_Str",entry.getInRoot());
}
 else {
String filename=entry.getPath().isEmpty() ? "String_Node_Str" + cleanForFile(entry.getId()) + (entry.isLitemod() ? "String_Node_Str" : "String_Node_Str") : entry.getPath();
generalFiles.add(new Downloadable(entry.getName(),filename,entry.getMD5(),100000,entry.getUrls()));
instData.addMod(entry.getId(),entry.getMD5(),filename);
}
modsLoaded++;
parent.log("String_Node_Str" + modsLoaded + "String_Node_Str"+ modCount+ "String_Node_Str");
}
Iterator<ConfigFile> itConfigs=configs.iterator();
while (itConfigs.hasNext()) {
final ConfigFile cfEntry=itConfigs.next();
final File confFile=instancePath.resolve(cfEntry.getPath()).toFile();
if (confFile.exists() && cfEntry.isNoOverwrite()) {
continue;
}
List<URL> configUrl=new ArrayList<URL>();
try {
configUrl.add(new URL(cfEntry.getUrl()));
}
 catch (MalformedURLException e) {
++errorCount;
apiLogger.log(Level.SEVERE,"String_Node_Str",e);
}
generalFiles.add(new Downloadable(cfEntry.getPath(),cfEntry.getPath(),cfEntry.getMD5(),10000,configUrl));
}
generalQueue=parent.submitNewQueue("String_Node_Str",server.getServerId(),generalFiles,instancePath.toFile(),DownloadCache.getDir());
jarQueue=parent.submitNewQueue("String_Node_Str",server.getServerId(),jarMods,tmpFolder,DownloadCache.getDir());
TaskableExecutor libExecutor=new TaskableExecutor(2,new Runnable(){
@Override public void run(){
for (String entry : libExtract) {
Archive.extractZip(instancePath.resolve("String_Node_Str").resolve(entry).toFile(),instancePath.resolve("String_Node_Str").resolve("String_Node_Str").toFile(),false);
}
}
}
);
libraryQueue.processQueue(libExecutor);
final File branding=new File(tmpFolder,"String_Node_Str");
try {
branding.createNewFile();
Properties propBrand=new Properties();
propBrand.setProperty("String_Node_Str","String_Node_Str" + server.getName() + "String_Node_Str"+ server.getRevision()+ "String_Node_Str");
propBrand.store(new FileOutputStream(branding),"String_Node_Str");
}
 catch (IOException e1) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e1);
}
final boolean doJarUpdate=updateJar;
TaskableExecutor jarExecutor=new TaskableExecutor(2,new Runnable(){
@Override public void run(){
if (!doJarUpdate) {
try {
Archive.updateArchive(productionJar.toFile(),new File[]{branding});
}
 catch (IOException e1) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e1);
}
}
 else {
for (Map.Entry<String,Boolean> entry : keepMeta.entrySet()) {
File entryFile=new File(tmpFolder,entry.getKey());
Archive.extractZip(entryFile,tmpFolder,entry.getValue());
entryFile.delete();
}
try {
buildJar.createNewFile();
}
 catch (IOException e) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e);
}
boolean doManifest=true;
List<File> buildList=recurseFolder(tmpFolder,true);
Iterator<File> blIt=new ArrayList<File>(buildList).iterator();
while (blIt.hasNext()) {
File entry=blIt.next();
if (entry.getPath().contains("String_Node_Str")) {
doManifest=false;
}
}
parent.log("String_Node_Str");
try {
Archive.createJar(buildJar,buildList,tmpFolder.getPath() + sep,doManifest);
}
 catch (IOException e1) {
parent.log("String_Node_Str");
apiLogger.log(Level.SEVERE,"String_Node_Str",e1);
}
try {
Files.copy(new Path(buildJar),productionJar);
}
 catch (IOException e) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e);
}
}
List<File> tempFiles=recurseFolder(tmpFolder,true);
ListIterator<File> li=tempFiles.listIterator(tempFiles.size());
while (li.hasPrevious()) {
File entry=li.previous();
entry.delete();
}
if (server.isGenerateList()) {
writeMCServerFile(server.getName(),server.getAddress(),server.getServerId());
}
instData.setMCVersion(server.getVersion());
instData.setRevision(server.getRevision());
String jsonOut=gson.toJson(instData);
try {
BufferedWriter writer=Files.newBufferedWriter(getInstanceRoot().resolve(server.getServerId()).resolve("String_Node_Str"));
writer.append(jsonOut);
writer.close();
}
 catch (IOException e) {
apiLogger.log(Level.SEVERE,"String_Node_Str",e);
}
}
}
);
jarQueue.processQueue(jarExecutor);
TaskableExecutor genExecutor=new TaskableExecutor(12,new Runnable(){
@Override public void run(){
for (Map.Entry<String,Boolean> entry : modExtract.entrySet()) {
if (entry.getValue()) {
Archive.extractZip(instancePath.resolve(entry.getKey()).toFile(),instancePath.toFile());
}
 else {
Archive.extractZip(instancePath.resolve(entry.getKey()).toFile(),instancePath.resolve("String_Node_Str").toFile());
}
instancePath.resolve(entry.getKey()).toFile().delete();
}
}
}
);
generalQueue.processQueue(genExecutor);
if (errorCount > 0) {
parent.baseLogger.severe("String_Node_Str");
return false;
}
return true;
}