Edit: I apologize for not explicating this. I am well aware that goto
is not currently a functional part of the Java language. This question is not about trying to use goto
in Java, it's about trying to not use it.
Edit: And, while I do appreciate help in the specific case given, this question is more looking towards whether there are deterministic methods applicable to the process of refactoring such code.
Hello all,
This is a question similar to this one but seeking to be more general.
In short, I am decompiling and modifying a class file, and I want to recompile it again for use, but I get ~25 errors, most of them relating to the use of goto
and related named blocks of code.
After looking around for quite some time, it seems my choices are to either pull a better decompiler than the ones I used out of the fabric of the internet, or untangle it myself and see if what I can make will compile properly.
My question is, are there any general guidelines that would be good to follow when attempting to convert goto statements into more sane/commonly accepted control flow keywords? So far it seems like recommendations have been on a case-by-case basis; are there ideas that can be applied across such exercises?
In case it helps, I'll post the relevant code here:
private void unpackNatives(CompleteVersion version, File targetDir)
throws IOException
{
OperatingSystem os;
Iterator iterator;
os = OperatingSystem.getCurrentPlatform();
Collection libraries = version.getRelevantLibraries();
iterator = libraries.iterator();
goto _L1
_L7:
ZipFile zip;
ExtractRules extractRules;
Library library = (Library)iterator.next();
Map nativesPerOs = library.getNatives();
if(nativesPerOs == null || nativesPerOs.get(os) == null)
continue; /* Loop/switch isn't completed */
File file = new File(Launcher.getInstance().getBaseDirectory(), (new StringBuilder("libraries/")).append(library.getArtifactPath((String)nativesPerOs.get(os))).toString());
zip = new ZipFile(file);
extractRules = library.getExtractRules();
Enumeration entries = zip.entries();
goto _L2
_L5:
BufferedInputStream inputStream;
byte buffer[];
FileOutputStream outputStream;
BufferedOutputStream bufferedOutputStream;
ZipEntry entry = (ZipEntry)entries.nextElement();
if(extractRules != null && !extractRules.shouldExtract(entry.getName()))
continue; /* Loop/switch isn't completed */
File targetFile = new File(targetDir, entry.getName());
if(targetFile.getParentFile() != null)
targetFile.getParentFile().mkdirs();
if(entry.isDirectory())
continue; /* Loop/switch isn't completed */
inputStream = new BufferedInputStream(zip.getInputStream(entry));
buffer = new byte[2048];
outputStream = new FileOutputStream(targetFile);
bufferedOutputStream = new BufferedOutputStream(outputStream);
int length;
while((length = inputStream.read(buffer, 0, buffer.length)) != -1)
bufferedOutputStream.write(buffer, 0, length);
goto _L3
Exception exception;
exception;
Downloadable.closeSilently(bufferedOutputStream);
Downloadable.closeSilently(outputStream);
Downloadable.closeSilently(inputStream);
throw exception;
_L3:
Downloadable.closeSilently(bufferedOutputStream);
Downloadable.closeSilently(outputStream);
Downloadable.closeSilently(inputStream);
_L2:
if(entries.hasMoreElements()) goto _L5; else goto _L4
_L4:
break MISSING_BLOCK_LABEL_339;
Exception exception1;
exception1;
zip.close();
throw exception1;
zip.close();
_L1:
if(iterator.hasNext()) goto _L7; else goto _L6
_L6:
}
This is my first question on SO, so help with format/tags is most welcome.