diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java index b95842f9..85b51fa7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/decompilers/impl/ASMifierGenerator.java @@ -21,12 +21,20 @@ package the.bytecode.club.bytecodeviewer.decompilers.impl; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.util.ASMifier; import org.objectweb.asm.util.TraceClassVisitor; +import the.bytecode.club.bytecodeviewer.Constants; +import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.decompilers.AbstractDecompiler; +import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; +import the.bytecode.club.bytecodeviewer.util.ExceptionUtils; import the.bytecode.club.bytecodeviewer.util.JavaFormatterUtils; import java.io.PrintWriter; import java.io.StringWriter; +import static the.bytecode.club.bytecodeviewer.Constants.NL; +import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.DEV_MODE_SIMULATED_ERROR; +import static the.bytecode.club.bytecodeviewer.translation.TranslatedStrings.ERROR; + /** * Objectweb ASMifier output * @@ -42,13 +50,32 @@ public class ASMifierGenerator extends AbstractDecompiler @Override public String decompileClassNode(ClassNode cn, byte[] bytes) { - StringWriter writer = new StringWriter(); - cn.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer))); - return JavaFormatterUtils.formatJavaCode(writer.toString()); + String exception; + + try + { + StringWriter writer = new StringWriter(); + cn.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer))); + + //handle simulated errors + if(Constants.DEV_FLAG_DECOMPILERS_SIMULATED_ERRORS) + throw new RuntimeException(DEV_MODE_SIMULATED_ERROR.toString()); + + //format and return the java writer contents + return JavaFormatterUtils.formatJavaCode(writer.toString()); + } + catch (Throwable e) + { + exception = ExceptionUtils.exceptionToString(e); + } + + return "ASMifier " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + NL + NL + + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + NL + NL + exception; } @Override public void decompileToZip(String sourceJar, String zipName) { + decompileToZipFallBack(sourceJar, zipName); } }