This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push:
new 2e4909b67 Better exception messages
2e4909b67 is described below
commit 2e4909b671cc38d39a00e05c56c20cf8939cc12e
Author: Gary D. Gregory <[email protected]>
AuthorDate: Mon Aug 18 07:55:43 2025 -0400
Better exception messages
---
.../commons/compress/archivers/tar/TarUtils.java | 33 +++++++++++-----------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git
a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
index 2b4832773..041418353 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
@@ -649,21 +649,21 @@ protected static List<TarArchiveStructSparse>
parsePAX1XSparseHeaders(final Inpu
long sparseHeadersCount = readResult[0];
if (sparseHeadersCount < 0) {
// overflow while reading number?
- throw new ArchiveException("Corrupted TAR archive. Negative value
in sparse headers block");
+ throw new ArchiveException("Corrupted TAR archive: Negative value
in sparse headers block.");
}
bytesRead += readResult[1];
while (sparseHeadersCount-- > 0) {
readResult = readLineOfNumberForPax1x(inputStream);
final long sparseOffset = readResult[0];
if (sparseOffset < 0) {
- throw new ArchiveException("Corrupted TAR archive. Sparse
header block offset contains negative value");
+ throw new ArchiveException("Corrupted TAR archive: Sparse
header block offset contains negative value.");
}
bytesRead += readResult[1];
readResult = readLineOfNumberForPax1x(inputStream);
final long sparseNumbytes = readResult[0];
if (sparseNumbytes < 0) {
- throw new ArchiveException("Corrupted TAR archive. Sparse
header block numbytes contains negative value");
+ throw new ArchiveException("Corrupted TAR archive: Sparse
header block numbytes contains negative value.");
}
bytesRead += readResult[1];
sparseHeaders.add(new TarArchiveStructSparse(sparseOffset,
sparseNumbytes));
@@ -763,17 +763,17 @@ protected static Map<String, String>
parsePaxHeaders(final InputStream inputStre
if (restLen <= 1) { // only NL
headers.remove(keyword);
} else if (headerSize >= 0 && restLen > headerSize
- totalRead) {
- throw new ArchiveException("Paxheader value
size %,d exceeds size of header record", restLen);
+ throw new ArchiveException("PAX header value
size %,d exceeds size of header record.", restLen);
} else {
final byte[] rest =
IOUtils.readRange(inputStream, restLen);
final int got = rest.length;
if (got != restLen) {
- throw new ArchiveException("Failed to read
Paxheader. Expected %,d bytes, read %,d", restLen, got);
+ throw new ArchiveException("Failed to read
PAX header: Expected %,d bytes, read %,d.", restLen, got);
}
totalRead += restLen;
// Drop trailing NL
if (rest[restLen - 1] != '\n') {
- throw new ArchiveException("Failed to read
Paxheader.Value should end with a newline");
+ throw new ArchiveException("Failed to read
PAX header: Value should end with a newline.");
}
final String value = new String(rest, 0,
restLen - 1, StandardCharsets.UTF_8);
headers.put(keyword, value);
@@ -786,21 +786,22 @@ protected static Map<String, String>
parsePaxHeaders(final InputStream inputStre
try {
offset = Long.valueOf(value);
} catch (final NumberFormatException ex) {
- throw new ArchiveException("Failed to
read Paxheader. Offset %s contains a non-numeric value",
TarGnuSparseKeys.OFFSET);
+ throw new ArchiveException("Failed to
read PAX header: Offset %s contains a non-numeric value.",
+ TarGnuSparseKeys.OFFSET);
}
if (offset < 0) {
- throw new ArchiveException("Failed to
read Paxheader. Offset %s contains negative value", TarGnuSparseKeys.OFFSET);
+ throw new ArchiveException("Failed to
read PAX header: Offset %s contains negative value.", TarGnuSparseKeys.OFFSET);
}
}
// for 0.0 PAX Headers
if (keyword.equals(TarGnuSparseKeys.NUMBYTES))
{
if (offset == null) {
- throw new ArchiveException("Failed to
read Paxheader. %s is expected before GNU.sparse.numbytes shows up.",
+ throw new ArchiveException("Failed to
read PAX header: %s is expected before GNU.sparse.numbytes shows up.",
TarGnuSparseKeys.OFFSET);
}
final long numbytes =
ParsingUtils.parseLongValue(value);
if (numbytes < 0) {
- throw new ArchiveException("Failed to
read Paxheader. %s contains negative value", TarGnuSparseKeys.NUMBYTES);
+ throw new ArchiveException("Failed to
read PAX header: %s contains negative value.", TarGnuSparseKeys.NUMBYTES);
}
sparseHeaders.add(new
TarArchiveStructSparse(offset, numbytes));
offset = null;
@@ -814,7 +815,7 @@ protected static Map<String, String> parsePaxHeaders(final
InputStream inputStre
}
// COMPRESS-530 : throw if we encounter a non-number while
reading length
if (!isAsciiDigit(ch)) {
- throw new ArchiveException("Failed to read Paxheader.
Encountered a non-number while reading length");
+ throw new ArchiveException("Failed to read PAX header:
Encountered a non-number while reading length.");
}
len *= 10;
len += ch - '0';
@@ -859,10 +860,10 @@ private static long[] readLineOfNumberForPax1x(final
InputStream inputStream) th
while ((number = inputStream.read()) != '\n') {
bytesRead += 1;
if (number == -1) {
- throw new ArchiveException("Unexpected EOF when reading parse
information of 1.X PAX format");
+ throw new ArchiveException("Unexpected EOF when reading parse
information of 1.X PAX format.");
}
if (!isAsciiDigit(number)) {
- throw new ArchiveException("Corrupted TAR archive. Non-numeric
value in sparse headers block");
+ throw new ArchiveException("Corrupted TAR archive: Non-numeric
value in sparse headers block.");
}
result = result * 10 + (number - '0');
}
@@ -908,15 +909,15 @@ static List<TarArchiveStructSparse>
readSparseStructs(final byte[] buffer, final
final TarArchiveStructSparse sparseHeader = parseSparse(buffer,
offset + i * (TarConstants.SPARSE_OFFSET_LEN +
TarConstants.SPARSE_NUMBYTES_LEN));
if (sparseHeader.getOffset() < 0) {
- throw new ArchiveException("Corrupted TAR archive, sparse
entry with negative offset");
+ throw new ArchiveException("Corrupted TAR archive: Sparse
entry with negative offset.");
}
if (sparseHeader.getNumbytes() < 0) {
- throw new ArchiveException("Corrupted TAR archive, sparse
entry with negative numbytes");
+ throw new ArchiveException("Corrupted TAR archive: sparse
entry with negative numbytes.");
}
sparseHeaders.add(sparseHeader);
} catch (final IllegalArgumentException e) {
// thrown internally by parseOctalOrBinary
- throw new ArchiveException("Corrupted TAR archive, sparse
entry is invalid", (Throwable) e);
+ throw new ArchiveException("Corrupted TAR archive: Sparse
entry is invalid.", (Throwable) e);
}
}
return Collections.unmodifiableList(sparseHeaders);