MuntashirAkon/AppManager · error · IllegalArgumentException

${fieldName} '${name}' is too long ( > ${NAMELEN} bytes)

Error message

${fieldName} '${name}' is too long ( > ${NAMELEN} bytes)

What it means

TarArchiveOutputStream throws this IllegalArgumentException from handleLongName when an entry's path or link name exceeds the tar format limit of TarConstants.NAMELEN (100) bytes and the long-file-mode is not set to GNU/PAX/ERROR mode. The classic tar header stores names in a fixed 100-byte field, so the writer refuses to silently truncate. It is thrown during putArchiveEntry when encoding the entry name.

Source

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

        if (len >= TarConstants.NAMELEN) {

            if (longFileMode == LONGFILE_POSIX) {
                paxHeaders.put(paxHeaderName, name);
                return true;
            } else if (longFileMode == LONGFILE_GNU) {
                // create a TarEntry for the LongLink, the contents
                // of which are the link's name
                final TarArchiveEntry longLinkEntry = new TarArchiveEntry(TarConstants.GNU_LONGLINK,
                    linkType);

                longLinkEntry.setSize(len + 1L); // +1 for NUL
                transferModTime(entry, longLinkEntry);
                putArchiveEntry(longLinkEntry);
                write(encodedName.array(), encodedName.arrayOffset(), len);
                write(0); // NUL terminator
                closeArchiveEntry();
            } else if (longFileMode != LONGFILE_TRUNCATE) {
                throw new IllegalArgumentException(fieldName + " '" + name //NOSONAR
                    + "' is too long ( > "
                    + TarConstants.NAMELEN + " bytes)");
            }
        }
        return false;
    }

    private void transferModTime(final TarArchiveEntry from, final TarArchiveEntry to) {
        Date fromModTime = from.getModTime();
        final long fromModTimeSeconds = fromModTime.getTime() / 1000;
        if (fromModTimeSeconds < 0 || fromModTimeSeconds > TarConstants.MAXSIZE) {
            fromModTime = new Date(0);
        }
        to.setModTime(fromModTime);
    }
}

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Call tarArchiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX) (or LONGFILE_GNU) before adding entries so long names are encoded in PAX/GNU extension headers
  2. Shorten the entry name via entry.setName(relativePath) or by archiving relative to a base directory instead of absolute paths
  3. If truncation is acceptable, setLongFileMode(LONGFILE_TRUNCATE) (the name will be cut at 100 bytes, likely unusable for extraction)
  4. Pre-validate entry names in application code and reject/log paths > 100 bytes before writing

Example fix

// before
TarArchiveOutputStream out = new TarArchiveOutputStream(fileOut);
out.putArchiveEntry(new TarArchiveEntry(file, file.getAbsolutePath())); // absolute path > 100 bytes
// after
TarArchiveOutputStream out = new TarArchiveOutputStream(fileOut);
out.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
out.putArchiveEntry(new TarArchiveEntry(file, relativize(file)));
Defensive patterns

Strategy: validation

Validate before calling

private static void validateName(TarArchiveEntry entry) {
    if (entry.getName().getBytes(StandardCharsets.UTF_8).length > TarConstants.NAMELEN) {
        throw new IllegalArgumentException("Entry name exceeds 100 tar bytes: " + entry.getName());
    }
}

Type guard

static boolean fitsInUstarHeader(TarArchiveEntry e) {
    return e.getName().getBytes(StandardCharsets.UTF_8).length <= 100;
}

Try / catch

try {
    out.putArchiveEntry(entry);
    // ... write contents
    out.closeArchiveEntry();
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("is too long")) {
        out.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
        out.putArchiveEntry(entry); // retry with PAX long-name support
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling putArchiveEntry() on a TarArchiveOutputStream with an entry whose getName() is longer than 100 bytes while longFileMode is LONGFILE_ERROR (the default); same for a link name on a symlink entry.

Common situations: Archiving files with very long paths (e.g. deep node_modules trees, machine-generated filenames); copying entries from other archive formats without name limits; not configuring GNU or PAX long-name support before writing.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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