{"record":{"id":"6df99cce04b89467","repo":"MuntashirAkon/AppManager","slug":"tar-record-size-must-always-be-512-bytes-attempt-to-set-size","errorCode":null,"errorMessage":"Tar record size must always be 512 bytes. Attempt to set size of ${recordSize}","messagePattern":"Tar record size must always be 512 bytes\\. Attempt to set size of (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java","lineNumber":180,"sourceCode":"    }\n\n    /**\n     * Constructor for TarArchiveOutputStream.\n     *\n     * @param os the output stream to use\n     * @param blockSize the block size to use . Must be a multiple of 512 bytes.\n     * @param recordSize the record size to use. Must be 512 bytes.\n     * @param encoding name of the encoding to use for file names\n     * @since 1.4\n     * @deprecated recordSize must always be 512 bytes. An IllegalArgumentException will be thrown\n     * if any other value is used.\n     */\n    @Deprecated\n    public TarArchiveOutputStream(final OutputStream os, final int blockSize,\n        final int recordSize, final String encoding) {\n        this(os, blockSize, encoding);\n        if (recordSize != RECORD_SIZE) {\n            throw new IllegalArgumentException(\n                \"Tar record size must always be 512 bytes. Attempt to set size of \" + recordSize);\n        }\n\n    }\n\n    /**\n     * Constructor for TarArchiveOutputStream.\n     *\n     * @param os the output stream to use\n     * @param blockSize the block size to use. Must be a multiple of 512 bytes.\n     * @param encoding name of the encoding to use for file names\n     * @since 1.4\n     */\n    public TarArchiveOutputStream(final OutputStream os, final int blockSize,\n        final String encoding) {\n        final int realBlockSize;\n        if (BLOCK_SIZE_UNSPECIFIED == blockSize) {\n            realBlockSize = RECORD_SIZE;","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java#L162-L198","documentation":"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.","triggerScenarios":"Calling the deprecated constructor new TarArchiveOutputStream(os, blockSize, recordSize, encoding) with any recordSize != 512 (e.g. 1024 or 10240).","commonSituations":"Porting code from other tar implementations that allow configurable record sizes; copying old Commons Compress examples; typos passing blockSize into the recordSize parameter.","solutions":["Pass 512 as recordSize (TarArchiveOutputStream.RECORD_SIZE).","Prefer the non-deprecated constructor TarArchiveOutputStream(os, blockSize, encoding), which uses the fixed 512-byte record size implicitly.","Check argument order — blockSize and recordSize are easy to swap."],"exampleFix":"// before\nnew TarArchiveOutputStream(out, 10240, 1024, \"UTF-8\");\n// after\nnew TarArchiveOutputStream(out, 10240, \"UTF-8\");","handlingStrategy":"validation","validationCode":"if (recordSize != 512) throw new IllegalArgumentException(\"recordSize must be 512\");","typeGuard":null,"tryCatchPattern":"try {\n    os = new TarArchiveOutputStream(out, blockSize, recordSize, enc);\n} catch (IllegalArgumentException e) {\n    os = new TarArchiveOutputStream(out, blockSize, enc); // fall back to default record size\n}","preventionTips":["Use the non-deprecated two/three-arg constructors","Reference TarArchiveOutputStream.RECORD_SIZE instead of literals","Check parameter order when migrating old code"],"tags":["tar","illegal-argument","deprecated-api","record-size"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}