MuntashirAkon/AppManager · error · IllegalArgumentException

Tar record size must always be 512 bytes. Attempt to set siz

Error message

Tar record size must always be 512 bytes. Attempt to set size of ${recordSize}

What it means

The deprecated TarArchiveOutputStream constructor requires the record size to be exactly 512 bytes, the only size tar supports. Any other value is rejected immediately with an IllegalArgumentException to prevent writing an invalid tar stream.

Source

Thrown at app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java:180

    }

    /**
     * Constructor for TarArchiveOutputStream.
     *
     * @param os the output stream to use
     * @param blockSize the block size to use . Must be a multiple of 512 bytes.
     * @param recordSize the record size to use. Must be 512 bytes.
     * @param encoding name of the encoding to use for file names
     * @since 1.4
     * @deprecated recordSize must always be 512 bytes. An IllegalArgumentException will be thrown
     * if any other value is used.
     */
    @Deprecated
    public TarArchiveOutputStream(final OutputStream os, final int blockSize,
        final int recordSize, final String encoding) {
        this(os, blockSize, encoding);
        if (recordSize != RECORD_SIZE) {
            throw new IllegalArgumentException(
                "Tar record size must always be 512 bytes. Attempt to set size of " + recordSize);
        }

    }

    /**
     * Constructor for TarArchiveOutputStream.
     *
     * @param os the output stream to use
     * @param blockSize the block size to use. Must be a multiple of 512 bytes.
     * @param encoding name of the encoding to use for file names
     * @since 1.4
     */
    public TarArchiveOutputStream(final OutputStream os, final int blockSize,
        final String encoding) {
        final int realBlockSize;
        if (BLOCK_SIZE_UNSPECIFIED == blockSize) {
            realBlockSize = RECORD_SIZE;

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Pass 512 as recordSize (TarArchiveOutputStream.RECORD_SIZE).
  2. Prefer the non-deprecated constructor TarArchiveOutputStream(os, blockSize, encoding), which uses the fixed 512-byte record size implicitly.
  3. Check argument order — blockSize and recordSize are easy to swap.

Example fix

// before
new TarArchiveOutputStream(out, 10240, 1024, "UTF-8");
// after
new TarArchiveOutputStream(out, 10240, "UTF-8");
Defensive patterns

Strategy: validation

Validate before calling

if (recordSize != 512) throw new IllegalArgumentException("recordSize must be 512");

Try / catch

try {
    os = new TarArchiveOutputStream(out, blockSize, recordSize, enc);
} catch (IllegalArgumentException e) {
    os = new TarArchiveOutputStream(out, blockSize, enc); // fall back to default record size
}

Prevention

When it happens

Trigger: Calling the deprecated constructor new TarArchiveOutputStream(os, blockSize, recordSize, encoding) with any recordSize != 512 (e.g. 1024 or 10240).

Common situations: Porting code from other tar implementations that allow configurable record sizes; copying old Commons Compress examples; typos passing blockSize into the recordSize parameter.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/6df99cce04b89467. Report an issue: GitHub.