{"record":{"id":"23033ee559c3c49c","repo":"pxb1988/dex2jar","slug":"section-sectiontype-start-with-different-posit","errorCode":null,"errorMessage":"section.sectionType + \" start with different position, planned:\" + section.offset + \", but is:\" + out.offset()","messagePattern":"section\\.sectionType \\+ \" start with different position, planned:\" \\+ section\\.offset \\+ \", but is:\" \\+ out\\.offset\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"dex-writer/src/main/java/com/googlecode/d2j/dex/writer/DexFileWriter.java","lineNumber":281,"sourceCode":"\n        Adler32 adler32 = new Adler32();\n        adler32.update(data, 12, size - 12);\n        int v = (int) adler32.getValue();\n        buffer.position(8);\n        buffer.putInt(v);\n    }\n\n    private void write(DataOut out) {\n        List<SectionItem<?>> list = new ArrayList<>(mapItem.items);\n        // mapItem is useless now\n        this.mapItem = null;\n        for (int i = 0; i < list.size(); i++) {\n            SectionItem<?> section = list.get(i);\n            list.set(i, null);\n            BaseItem.addPadding(out, out.offset(),\n                    section.sectionType.alignment);\n            if (out.offset() != section.offset) {\n                throw new RuntimeException(section.sectionType\n                        + \" start with different position, planned:\"\n                        + section.offset + \", but is:\" + out.offset());\n            }\n            section.write(out);\n        }\n    }\n\n    private int place() {\n        // 2. order\n        mapItem.cleanZeroSizeEntry();\n\n        // 3. place\n        int offset = 0;\n        // int index = 0;\n        for (SectionItem<?> section : mapItem.items) {\n\n            offset = BaseItem.padding(offset, section.sectionType.alignment);\n            section.offset = offset;","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-writer/src/main/java/com/googlecode/d2j/dex/writer/DexFileWriter.java#L263-L299","documentation":"During DexFileWriter.write(), each section is padding-aligned then compared to its pre-calculated offset. If the accumulated output offset differs from the planned section.offset, the layout invariant is broken and a RuntimeException naming the section type is thrown.","triggerScenarios":"toByteArray() -> write() with sections whose sizes or alignment padding were computed inconsistently; items that changed size after offset planning (e.g. late mutation of items between planning and writing).","commonSituations":"Custom section/item implementations; mutating items after offset calculation; library bugs when certain combined sections shift alignment.","solutions":["Do not modify items after the layout/offset phase and before toByteArray()","Audit custom BaseItem.addPadding/alignment values for the reported sectionType","Upgrade the dex-writer version or file a bug with a reproducing dex"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { dexFileWriter.toByteArray(); } catch (RuntimeException e) { if (String.valueOf(e.getMessage()).contains(\"start with different position\")) { /* log section name from message */ } throw e; }","preventionTips":["Freeze all items before layout","Match alignment values with the dex spec for each section","Test with large inputs where padding effects accumulate"],"tags":["dex","writer","offset-mismatch"],"backgroundTag":"internal-invariant-violation","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}