pxb1988/dex2jar · critical · RuntimeException

section.sectionType + " start with different position…

Error message

section.sectionType + " start with different position, planned:" + section.offset + ", but is:" + out.offset()

What it means

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.

Solutions

  1. Do not modify items after the layout/offset phase and before toByteArray()
  2. Audit custom BaseItem.addPadding/alignment values for the reported sectionType
  3. Upgrade the dex-writer version or file a bug with a reproducing dex
Defensive patterns

Strategy: try-catch

Try / catch

try { dexFileWriter.toByteArray(); } catch (RuntimeException e) { if (String.valueOf(e.getMessage()).contains("start with different position")) { /* log section name from message */ } throw e; }

Prevention

When it happens

Trigger: 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).

Common situations: Custom section/item implementations; mutating items after offset calculation; library bugs when certain combined sections shift alignment.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08). Data as JSON: /api/errors/23033ee559c3c49c. Report an issue: GitHub.

Appendix: source

Thrown at dex-writer/src/main/java/com/googlecode/d2j/dex/writer/DexFileWriter.java:281

        Adler32 adler32 = new Adler32();
        adler32.update(data, 12, size - 12);
        int v = (int) adler32.getValue();
        buffer.position(8);
        buffer.putInt(v);
    }

    private void write(DataOut out) {
        List<SectionItem<?>> list = new ArrayList<>(mapItem.items);
        // mapItem is useless now
        this.mapItem = null;
        for (int i = 0; i < list.size(); i++) {
            SectionItem<?> section = list.get(i);
            list.set(i, null);
            BaseItem.addPadding(out, out.offset(),
                    section.sectionType.alignment);
            if (out.offset() != section.offset) {
                throw new RuntimeException(section.sectionType
                        + " start with different position, planned:"
                        + section.offset + ", but is:" + out.offset());
            }
            section.write(out);
        }
    }

    private int place() {
        // 2. order
        mapItem.cleanZeroSizeEntry();

        // 3. place
        int offset = 0;
        // int index = 0;
        for (SectionItem<?> section : mapItem.items) {

            offset = BaseItem.padding(offset, section.sectionType.alignment);
            section.offset = offset;

View on GitHub (pinned to b5bda4fb49)