#2963·jadx

Decompiled output is often not valid Java: illegal statements emitted from control flow, constructors, exceptions and identifier renaming

Author: zgyhimCreated Sep 25, 2026Updated Sep 25, 2026

Summary

While recovering a decompiled Android app (an APK) back to a compilable Gradle project, I had to manually fix a large number of compilation errors in JADX output. Several are not merely "ugly" or "unreadable" — they are illegal Java and always fail javac. They also hurt readability, because a reader cannot tell valid control flow from a decompiler artifact without compiling.

The common root cause is that JADX emits something close to the bytecode structure instead of re-imposing Java source-level rules (checked exceptions, generic bounds, definite assignment, declaration ordering, constructor chaining). Below are the concrete, reproducible patterns I observed.

Environment

  • JADX version: not recorded in the provided output (only /* JADX INFO: loaded from: classes.dex */ and the usual JADX WARN/INFO markers). I can bisect a version if required.
  • Target: Java 8 source level, Android app, javac 17 (with --release 8).
  • I can provide the full decompiled sources and/or the original APK on request.

Invalid-Java cases

1. return; emitted inside a static { } initializer

JADX reconstructs <clinit> early-exit branches as return;, which is illegal in a static initializer.

Actual:

java
static {
    int version = Build.VERSION.SDK_INT;
    if (version >= 21) { IMPL = new Api21ViewCompatImpl(); return; }
    if (version >= 19) { IMPL = new KitKatViewCompatImpl(); return; }
    ...
}

Expected: an if / else if chain (no return).

Observed in ~10 files (e.g. ViewCompat, BitmapCompat, DrawableCompat, ConnectivityManagerCompat, ViewGroupCompat, ViewConfigurationCompat, ViewPropertyAnimatorCompat, AccessibilityNodeInfoCompat, AccessibilityRecordCompat, NotificationCompat).

2. Delegating this(...) / super(...) is not the first statement

Actual:

java
public ZipArchiveEntry(File inputFile, String entryName) {
    if (inputFile.isDirectory() && !entryName.endsWith("/")) {
        entryName = entryName + "/";
    }
    this(entryName);          // compile error: not first statement
    ...
}

Also:

java
public CircleImageView(Context context, int color, float radius) {
    ShapeDrawable circle;     // local declaration before super()
    super(context);
    ...
}

Expected: fold the pre-processing into the argument expression of this(...), and move locals after the super(...) call.

3. Assignment vs. comparison precedence

Actual:

java
if (this.buf.lengthOfLastRead = this.f49in.read(this.buf.buf) == -1) { ... }
...
if (this.buf.lengthOfLastRead = this.f49in.read(this.buf.buf) <= 0) { ... }

This is parsed as x = (read(...) == -1), i.e. assigning a boolean to an int — compile error. Expected:

java
this.buf.lengthOfLastRead = this.f49in.read(this.buf.buf);
if (this.buf.lengthOfLastRead == -1) { ... }

4. Loop exit condition lost -> while (true) and unreachable code

Actual:

java
while (i2 < shorterBlocksNumDataCodewords) {
    int j = 0;
    while (true) {
        rawCodewordsOffset3 = rawCodewordsOffset4;
        if (j < numResultBlocks) {
            rawCodewordsOffset4 = rawCodewordsOffset3 + 1;
            result[j].codewords[i2] = rawCodewords[rawCodewordsOffset3];
            j++;
        }
    }
    i2++;   // error: unreachable
}

Expected: while (j < numResultBlocks) { ... }.

Also emitted: a break; outside any loop/switch:

java
} else {
    Log.d(...);
    break;      // error: break outside switch or loop
}

5. Checked-exception signature widened to a common supertype

Actual:

java
// interface Reader
Result decode(BinaryBitmap, Map<DecodeHintType, ?>) throws NotFoundException, ChecksumException, FormatException;

// implementation emitted by JADX
public final Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws ReaderException { ... }

ReaderException is the common supertype, so the override widens the checked exception set — illegal. JADX loses the precise throws list and this frequently breaks overrides.

6. Collision rename breaks an interface contract

Actual:

java
public interface Mutable<T> {
    /* JADX INFO: renamed from: getValue */
    T getValue2();
    void setValue(T t);
}
// impl
public class MutableBoolean implements Mutable<Boolean> {
    @Override public Boolean getValue() { ... }   // does not implement getValue2()
}

The rename is applied inconsistently between the interface and some implementations, so the class no longer satisfies the interface.

7. Unqualified nested type in extends (forward reference)

Actual:

java
public class MultiBackgroundInitializer
        extends BackgroundInitializer<MultiBackgroundInitializerResults> {   // not in scope here
    public static class MultiBackgroundInitializerResults { ... }
}

extends clauses are outside the member-type scope, so the reference must be qualified:

java
extends BackgroundInitializer<MultiBackgroundInitializer.MultiBackgroundInitializerResults>

8. try/finally lowering artifacts (readability + correctness risk)

Actual patterns:

java
} catch (Throwable th) {
    th = th;                 // self-assignment
    ...
}
...
} catch (Throwable th2) {
    th = th2;                // `th` never declared
}

and:

java
if (0 == 0 && ji != null) { ji.close(); }   // always-true condition
if (1 == 0 && ji2 != null) { ji2.close(); } // always-false: resource never closed

and duplicated close() blocks for the same resource. Beyond being noisy, the 1 == 0 form can silently drop cleanup. This is the single largest source of manual fixes in my run.

Secondary / arguably inherent

9. Generic information loss

JADX emits raw/erased types that fail compilation, e.g.:

  • List<Object> vs List<AccessibilityNodeInfo> on override,
  • Class<CAP#1> vs Class<L>,
  • Enum added to EnumSet<E>,
  • Comparator<?> used where Comparator<Object> is needed,
  • diamond new MapStrLookup<>(...) inference failure.

I understand erased generics are not fully recoverable; listing for completeness and to ask whether some heuristics (e.g. preferring the declared return/param type from the enclosing signature) could reduce the noise.

Impact

  • Decompiled output cannot be compiled without per-site manual repair, and the repairs are not mechanical — a reader must reason about original control flow and checked-exception contracts.
  • Readability suffers too: return; in static blocks, while (true) with no exit, self-assignments and 0 == 0/1 == 0 conditions make it impossible to distinguish real logic from decompiler noise without compiling.
  • These were the dominant blockers in a ~105-error list; items 1-7 are unambiguous "must not emit" cases.

Request

  1. Treat "output must be valid Java" as a lint-level invariant: at minimum avoid return; in initializers, break; outside loops, statements before this()/super(), and widened checked exceptions.
  2. Improve <clinit> early-exit rendering to if/else if.
  3. Restore assignment/comparison as two statements rather than chained ternary assignment.
  4. Keep interface/implementation renames consistent (or emit the original name).
  5. Reduce try/finally artifacts (th = th;, constant conditions, duplicated cleanup).

I'm happy to split this into separate issues or provide minimal class files if that helps triage.


This report was drafted with AI assistance (deepseek-v4-flash) on 2026-09-25, based on observed compiler output during a manual restoration; all code snippets are copied from actual decompiled output.