From: Dominik Stadler Date: Sun, 10 Apr 2022 16:44:58 +0000 (+0000) Subject: Rework message when reaching allocation limits X-Git-Tag: REL_5_2_3~361 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d970319239e0886997ba0b6c8b9a82b553368694;p=poi.git Rework message when reaching allocation limits Also remove a useless Math.min() as the previous condition already indicates which one is the smaller value git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899708 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java index cf40645138..8d80c7b7d8 100644 --- a/poi/src/main/java/org/apache/poi/util/IOUtils.java +++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java @@ -63,7 +63,7 @@ public final class IOUtils { /** * The default size of the bytearray used while reading input streams. This is meant to be pretty small. */ - private static int DEFAULT_BUFFER_SIZE = 4096; + private static final int DEFAULT_BUFFER_SIZE = 4096; private IOUtils() { // no instances of this class @@ -262,7 +262,7 @@ public final class IOUtils { final int derivedLen = Math.min(length, maxLength); final int bufferLen = isLengthKnown ? derivedLen : Math.min(DEFAULT_BUFFER_SIZE, derivedLen); if (MAX_BYTE_ARRAY_INIT_SIZE > 0 && bufferLen > MAX_BYTE_ARRAY_INIT_SIZE) { - return Math.min(bufferLen, MAX_BYTE_ARRAY_INIT_SIZE); + return MAX_BYTE_ARRAY_INIT_SIZE; } return bufferLen; } @@ -598,21 +598,16 @@ public final class IOUtils { private static void throwRFE(long length, int maxLength) { throw new RecordFormatException(String.format(Locale.ROOT, "Tried to allocate an array of length %,d" + ", but the maximum length for this record type is %,d.\n" + - "If the file is not corrupt or large, please open an issue on bugzilla to request \n" + + "If the file is not corrupt and not large, please open an issue on bugzilla to request \n" + "increasing the maximum allowable size for this record type.\n"+ - "As a temporary workaround, consider setting a higher override value with " + - "IOUtils.setByteArrayMaxOverride()", - length, maxLength)); - + "You can set a higher override value with IOUtils.setByteArrayMaxOverride()", length, maxLength)); } private static void throwRecordTruncationException(final int maxLength) { throw new RecordFormatException(String.format(Locale.ROOT, "Tried to read data but the maximum length " + "for this record type is %,d.\n" + - "If the file is not corrupt or large, please open an issue on bugzilla to request \n" + + "If the file is not corrupt and not large, please open an issue on bugzilla to request \n" + "increasing the maximum allowable size for this record type.\n"+ - "As a temporary workaround, consider setting a higher override value with " + - "IOUtils.setByteArrayMaxOverride()", maxLength)); - + "You can set a higher override value with IOUtils.setByteArrayMaxOverride()", maxLength)); } }