{"record":{"id":"94a9289c5b24d886","repo":"Tencent/tinker","slug":"illegal-dex-format-there-s-at-least-one-loop-in-c","errorCode":null,"errorMessage":"Illegal dex format, there's at least one loop in class inheritance graph.","messagePattern":"Illegal dex format, there's at least one loop in class inheritance graph\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"tinker-commons/src/main/java/com/tencent/tinker/commons/dexpatcher/algorithms/patch/ClassDefSectionPatchAlgorithm.java","lineNumber":145,"sourceCode":"        }\n\n        final List<ClassDef> result = new ArrayList<>();\n        while (!typeIdWithZeroInDegrees.isEmpty()) {\n            final int currentTypeId = typeIdWithZeroInDegrees.poll();\n            result.add(typeIdToClassDefMap.get(currentTypeId));\n\n            for (int nextTypeId : typeGraph.get(currentTypeId)) {\n                final int newInDegree = inDegrees.get(nextTypeId) - 1;\n                inDegrees.put(nextTypeId, newInDegree);\n                if (newInDegree == 0) {\n                    typeIdWithZeroInDegrees.offer(nextTypeId);\n                }\n            }\n        }\n\n        // Check if type graph contains loop.\n        if (result.size() != elements.size()) {\n            throw new IllegalStateException(\"Illegal dex format, there's at least one loop in class inheritance graph.\");\n        }\n\n        return result;\n    }\n}\n","sourceCodeStart":127,"sourceCodeEnd":151,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-commons/src/main/java/com/tencent/tinker/commons/dexpatcher/algorithms/patch/ClassDefSectionPatchAlgorithm.java#L127-L151","documentation":"IllegalStateException from ClassDefSectionPatchAlgorithm's topological sort: after Kahn's algorithm over the class inheritance graph (superclass/interface type-id edges), fewer classes were emitted than exist — meaning the graph has a cycle. A legal dex cannot have cyclic inheritance, so the input dex is invalid.","triggerScenarios":"Diffing or patching a dex whose class_def items form a superclass cycle (class A extends B, B extends A), which the sort in sortTypeListByInheritanceDetection cannot order.","commonSituations":"Malformed dex produced by experimental toolchains or protectors; hand-edited dex; corrupted dex where type indices point at wrong entries.","solutions":["Validate the dex with standard tooling (dexdump/baksmali) and rebuild the offending module","Exclude the corrupt dex from patching if only one is affected","Report a Tinker issue with the dex if it passes standard validation yet still cycles"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    // dex diff/patch\n} catch (IllegalStateException e) {\n    if (String.valueOf(e.getMessage()).contains(\"loop in class inheritance graph\")) {\n        // input dex is invalid: quarantine it and report\n    } else { throw e; }\n}","preventionTips":["Run dexdump/baksmali verification on third-party or protected dex before patching","Treat inheritance-cycle errors as data corruption, never retry the same input"],"tags":["dexpatcher","classdef","cycle-detection","malformed-dex"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}