{"record":{"id":"09548397b2dc1f0e","repo":"skylot/jadx","slug":"init-of-enum-field-uses-external-variables","errorCode":null,"errorMessage":"Init of enum field '{}' uses external variables","messagePattern":"Init of enum field '(.+?)' uses external variables","errorType":"exception","errorClass":"JadxRuntimeException","httpStatus":null,"severity":"error","filePath":"jadx-core/src/main/java/jadx/core/dex/visitors/EnumVisitor.java","lineNumber":485,"sourceCode":"\t\t\treturn null;\n\t\t}\n\t\t// usually constructor signature is '<init>(Ljava/lang/String;I)V'\n\t\t// sometimes one or both args can be inlined or omitted\n\t\tString nameStr = null;\n\t\tif (co.getArgsCount() == 0) {\n\t\t\tConstructorInsn ctrInsn = searchEnumSuperCtrInsn(ctrMth);\n\t\t\tif (ctrInsn != null && ctrInsn.getArgsCount() != 0) {\n\t\t\t\tnameStr = getConstString(ctrMth.root(), ctrInsn.getArg(0));\n\t\t\t}\n\t\t} else {\n\t\t\tnameStr = getConstString(cls.root(), co.getArg(0));\n\t\t\t// verify and try to inline additional constructor args\n\t\t\tList<RegisterArg> regs = new ArrayList<>();\n\t\t\tco.getRegisterArgs(regs);\n\t\t\tif (!regs.isEmpty()) {\n\t\t\t\tConstructorInsn replacedCo = inlineExternalRegs(data, co);\n\t\t\t\tif (replacedCo == null) {\n\t\t\t\t\tthrow new JadxRuntimeException(\"Init of enum field '\" + enumFieldNode.getName() + \"' uses external variables\");\n\t\t\t\t}\n\t\t\t\tdata.toRemove.add(co);\n\t\t\t\tco = replacedCo;\n\t\t\t}\n\t\t}\n\t\treturn new EnumField(enumFieldNode, co, nameStr);\n\t}\n\n\tprivate @Nullable ConstructorInsn searchEnumSuperCtrInsn(MethodNode ctrMth) {\n\t\tfor (BlockNode block : ctrMth.getBasicBlocks()) {\n\t\t\tfor (InsnNode insn : block.getInstructions()) {\n\t\t\t\tif (insn.getType() == InsnType.CONSTRUCTOR) {\n\t\t\t\t\tConstructorInsn ctrCall = (ConstructorInsn) insn;\n\t\t\t\t\tif (ctrCall.isSuper()\n\t\t\t\t\t\t\t&& ctrCall.getArgsCount() != 0\n\t\t\t\t\t\t\t&& ctrCall.getCallMth().getRawFullId().equals(ENUM_SUPER_CONSTRUCTOR_ID)) {\n\t\t\t\t\t\treturn ctrCall;\n\t\t\t\t\t}","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-core/src/main/java/jadx/core/dex/visitors/EnumVisitor.java#L467-L503","documentation":"Thrown by EnumVisitor when processing an enum constant's constructor call and finding that the constructor arguments reference register variables that cannot be inlined (inlineExternalRegs returns null). Enum constant initialisation should use only constant/literal values; references to external registers indicate the enum's $VALUES or <clinit> uses computed values that jadx cannot statically resolve.","triggerScenarios":"During enum class processing, a ConstructorInsn (co) for an enum field has register args (co.getRegisterArgs(regs) is non-empty). inlineExternalRegs(data, co) is called to resolve them but returns null — the registers reference values from outside the static initialiser that cannot be folded into constants.","commonSituations":"Enums in obfuscated code where the compiler or obfuscator generates complex <clinit> logic with shared registers. Also seen when an enum's constructor arguments are computed at runtime rather than being literals. Standard enum patterns (enum E { A, B }) work fine.","solutions":["Upgrade jadx — enum-handling heuristics improve with each release.","Catch JadxRuntimeException per class and skip the enum, allowing other classes to decompile.","Report the issue with the enum class name and field name from the error message.","Try alternative decompiler settings or tools for the specific class."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    javaClass.decompile();\n} catch (JadxRuntimeException e) {\n    LOG.warn(\"Enum init with external vars in {}: {}\", javaClass.getName(), e.getMessage());\n}","preventionTips":["Upgrade jadx for improved enum-handling heuristics.","Catch per class to continue the batch.","Report obfuscated enum patterns that trigger the failure.","Use alternative decompiler settings or tools for the specific enum class."],"tags":["jadx","decompiler","enum","constructor","register-inline","obfuscation"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}