Skip to content

Commit

Permalink
Propagate exceptions from pre-processing step
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Sep 4, 2023
1 parent e1caf59 commit 27ceca6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
28 changes: 16 additions & 12 deletions src/org/jetbrains/java/decompiler/main/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,29 @@ 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<String> 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;
}

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<String> 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) {
Expand Down
6 changes: 5 additions & 1 deletion src/org/jetbrains/java/decompiler/struct/ContextUnit.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -173,7 +175,9 @@ public void save(final Function<String, StructClass> 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;
}

Expand Down

0 comments on commit 27ceca6

Please sign in to comment.