skylot/jadx · error · JadxRuntimeException

Unknown loop type:

Error message

Unknown loop type: 

What it means

Thrown by RegionGen when generating a loop region whose LoopType is neither ForLoop nor ForEachLoop. These are the only two concrete loop types in jadx's region model. Hitting this exception means a new LoopType subclass exists or the region tree was corrupted to contain an unexpected loop type.

Source

Thrown at jadx-core/src/main/java/jadx/core/codegen/RegionGen.java:211

				code.add(") {");
				CodeGenUtils.addCodeComments(code, mth, condInsn);
				makeRegionIndent(code, region.getBody());
				code.startLine('}');
				return;
			}
			if (type instanceof ForEachLoop) {
				ForEachLoop forEachLoop = (ForEachLoop) type;
				code.add("for (");
				declareVar(code, forEachLoop.getVarArg());
				code.add(" : ");
				addArg(code, forEachLoop.getIterableArg(), false);
				code.add(") {");
				CodeGenUtils.addCodeComments(code, mth, condInsn);
				makeRegionIndent(code, region.getBody());
				code.startLine('}');
				return;
			}
			throw new JadxRuntimeException("Unknown loop type: " + type.getClass());
		}
		if (region.isConditionAtEnd()) {
			code.add("do {");
			CodeGenUtils.addCodeComments(code, mth, condInsn);
			makeRegionIndent(code, region.getBody());
			code.startLineWithNum(region.getSourceLine());
			code.add("} while (");
			conditionGen.add(code, condition);
			code.add(");");
		} else {
			code.add("while (");
			conditionGen.add(code, condition);
			code.add(") {");
			CodeGenUtils.addCodeComments(code, mth, condInsn);
			makeRegionIndent(code, region.getBody());
			code.startLine('}');
		}
	}

View on GitHub (pinned to e738a26571)

Solutions

  1. If you added a new LoopType subclass, add an instanceof check and handling in RegionGen.
  2. Report as an internal jadx bug with the class and stack trace.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    regionGen.makeRegion(code, region);
} catch (JadxRuntimeException e) {
    if (e.getMessage().startsWith("Unknown loop type")) {
        code.startLine("/* unknown loop type: " + loopType.getClass() + " */");
        logger.warn("Unhandled loop type in codegen", e);
        // Continue with other regions
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: A LoopRegion whose getLoop() returns a LoopType implementation other than ForLoop or ForEachLoop. Adding a new loop type (e.g., a WhileLoop abstraction) without updating RegionGen. Internal corruption of the region tree.

Common situations: Contributing new loop abstractions to jadx without updating all consumers. Extremely rare in user-facing decompilation — this is a developer-facing exhaustive-type-check guard.

Related errors


AI-assisted analysis of skylot/jadx@e738a26571 (2026-08-14). Data as JSON: /api/errors/508a320f58379f66. Report an issue: GitHub.