From 27ceca6ad5a54086adce10cd812b11e56306c6ca Mon Sep 17 00:00:00 2001 From: Jasmine Karthikeyan <25208576+jaskarth@users.noreply.github.com> Date: Sun, 3 Sep 2023 20:16:35 -0400 Subject: [PATCH] Propagate exceptions from pre-processing step --- .../java/decompiler/main/ClassWriter.java | 28 +++++++++++-------- .../java/decompiler/struct/ContextUnit.java | 6 +++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index f98ed0b0c2..16f6a4fbf4 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -117,18 +117,7 @@ private static boolean invokeProcessors(TextBuffer buffer, ClassNode node) { DecompilerContext.getLogger().writeMessage("Class " + node.simpleName + " couldn't be written.", IFernflowerLogger.Severity.WARN, t); - buffer.append("// $VF: Couldn't be decompiled"); - buffer.appendLineSeparator(); - if (DecompilerContext.getOption(IFernflowerPreferences.DUMP_EXCEPTION_ON_ERROR)) { - List lines = new ArrayList<>(); - lines.addAll(ClassWriter.getErrorComment()); - collectErrorLines(t, lines); - for (String line : lines) { - buffer.append("//"); - if (!line.isEmpty()) buffer.append(' ').append(line); - buffer.appendLineSeparator(); - } - } + writeException(buffer, t); return false; } @@ -136,6 +125,21 @@ private static boolean invokeProcessors(TextBuffer buffer, ClassNode node) { return true; } + public static void writeException(TextBuffer buffer, Throwable t) { + buffer.append("// $VF: Couldn't be decompiled"); + buffer.appendLineSeparator(); + if (DecompilerContext.getOption(IFernflowerPreferences.DUMP_EXCEPTION_ON_ERROR)) { + List lines = new ArrayList<>(); + lines.addAll(ClassWriter.getErrorComment()); + collectErrorLines(t, lines); + for (String line : lines) { + buffer.append("//"); + if (!line.isEmpty()) buffer.append(' ').append(line); + buffer.appendLineSeparator(); + } + } + } + public void classLambdaToJava(ClassNode node, TextBuffer buffer, Exprent method_object, int indent) { ClassWrapper wrapper = node.getWrapper(); if (wrapper == null) { diff --git a/src/org/jetbrains/java/decompiler/struct/ContextUnit.java b/src/org/jetbrains/java/decompiler/struct/ContextUnit.java index 807425db8f..b949922a76 100644 --- a/src/org/jetbrains/java/decompiler/struct/ContextUnit.java +++ b/src/org/jetbrains/java/decompiler/struct/ContextUnit.java @@ -1,11 +1,13 @@ // Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler.struct; +import org.jetbrains.java.decompiler.main.ClassWriter; import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.extern.IContextSource; import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger; import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; import org.jetbrains.java.decompiler.main.extern.IResultSaver; +import org.jetbrains.java.decompiler.util.TextBuffer; import java.io.IOException; import java.io.InputStream; @@ -173,7 +175,9 @@ public void save(final Function loader) throws IOException // emit for (final ClassContext classCtx : toDump) { if (classCtx.pendingError != null) { - classCtx.classContent = "error"; // TODO + TextBuffer buf = new TextBuffer(); + ClassWriter.writeException(buf, classCtx.pendingError); + classCtx.classContent = buf.convertToStringAndAllowDataDiscard(); continue; }