Skip to content

Commit 8814b6d

Browse files
committed
Replace "Invalid" with "Illegal" in some exception messages
1 parent c93030a commit 8814b6d

8 files changed

Lines changed: 28 additions & 28 deletions

File tree

src/main/java/org/apache/commons/io/IOCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public enum IOCase {
7777
*/
7878
public static IOCase forName(final String name) {
7979
return Stream.of(IOCase.values()).filter(ioCase -> ioCase.getName().equals(name)).findFirst()
80-
.orElseThrow(() -> new IllegalArgumentException("Invalid IOCase name: " + name));
80+
.orElseThrow(() -> new IllegalArgumentException("Illegal IOCase name: " + name));
8181
}
8282

8383
/**

src/main/java/org/apache/commons/io/input/XmlStreamReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ public Builder setLenient(final boolean lenient) {
191191
*/
192192
public static final Pattern ENCODING_PATTERN = Pattern.compile("<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:'.[^']*'))", Pattern.MULTILINE);
193193

194-
private static final String RAW_EX_1 = "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch";
194+
private static final String RAW_EX_1 = "Illegal encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch";
195195

196-
private static final String RAW_EX_2 = "Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM";
196+
private static final String RAW_EX_2 = "Illegal encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM";
197197

198-
private static final String HTTP_EX_1 = "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL";
198+
private static final String HTTP_EX_1 = "Illegal encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL";
199199

200-
private static final String HTTP_EX_2 = "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch";
200+
private static final String HTTP_EX_2 = "Illegal encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch";
201201

202-
private static final String HTTP_EX_3 = "Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Invalid MIME";
202+
private static final String HTTP_EX_3 = "Illegal encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Illegal MIME";
203203

204204
/**
205205
* Constructs a new {@link Builder}.

src/main/java/org/apache/commons/io/input/buffer/CircularBufferInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public CircularBufferInputStream(final InputStream inputStream) {
5959
public CircularBufferInputStream(final InputStream inputStream, final int bufferSize) {
6060
super(Objects.requireNonNull(inputStream, "inputStream"));
6161
if (bufferSize <= 0) {
62-
throw new IllegalArgumentException("Invalid bufferSize: " + bufferSize);
62+
throw new IllegalArgumentException("Illegal bufferSize: " + bufferSize);
6363
}
6464
this.buffer = new CircularByteBuffer(bufferSize);
6565
this.bufferSize = bufferSize;

src/main/java/org/apache/commons/io/input/buffer/CircularByteBuffer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public void add(final byte value) {
8787
public void add(final byte[] targetBuffer, final int offset, final int length) {
8888
Objects.requireNonNull(targetBuffer, "Buffer");
8989
if (offset < 0 || offset >= targetBuffer.length) {
90-
throw new IllegalArgumentException("Invalid offset: " + offset);
90+
throw new IllegalArgumentException("Illegal offset: " + offset);
9191
}
9292
if (length < 0) {
93-
throw new IllegalArgumentException("Invalid length: " + length);
93+
throw new IllegalArgumentException("Illegal length: " + length);
9494
}
9595
if (currentNumberOfBytes + length > buffer.length) {
9696
throw new IllegalStateException("No space available");
@@ -182,10 +182,10 @@ public boolean hasSpace(final int count) {
182182
public boolean peek(final byte[] sourceBuffer, final int offset, final int length) {
183183
Objects.requireNonNull(sourceBuffer, "Buffer");
184184
if (offset < 0 || offset >= sourceBuffer.length) {
185-
throw new IllegalArgumentException("Invalid offset: " + offset);
185+
throw new IllegalArgumentException("Illegal offset: " + offset);
186186
}
187187
if (length < 0 || length > buffer.length) {
188-
throw new IllegalArgumentException("Invalid length: " + length);
188+
throw new IllegalArgumentException("Illegal length: " + length);
189189
}
190190
if (length < currentNumberOfBytes) {
191191
return false;
@@ -239,10 +239,10 @@ public byte read() {
239239
public void read(final byte[] targetBuffer, final int targetOffset, final int length) {
240240
Objects.requireNonNull(targetBuffer, "targetBuffer");
241241
if (targetOffset < 0 || targetOffset >= targetBuffer.length) {
242-
throw new IllegalArgumentException("Invalid offset: " + targetOffset);
242+
throw new IllegalArgumentException("Illegal offset: " + targetOffset);
243243
}
244244
if (length < 0 || length > buffer.length) {
245-
throw new IllegalArgumentException("Invalid length: " + length);
245+
throw new IllegalArgumentException("Illegal length: " + length);
246246
}
247247
if (targetOffset + length > targetBuffer.length) {
248248
throw new IllegalArgumentException("The supplied byte array contains only "

src/test/java/org/apache/commons/io/FileUtilsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ public long length() {
142142
private static final String UTF_8 = StandardCharsets.UTF_8.name();
143143

144144
/** Test data. */
145-
private static final long DATE3 = 1000000002000L;
145+
private static final long DATE3 = 1_000_000_002_000L;
146146

147147
/** Test data. */
148-
private static final long DATE2 = 1000000001000L;
148+
private static final long DATE2 = 1_000_000_001_000L;
149149

150150
/** Test data. */
151-
private static final long DATE1 = 1000000000000L;
151+
private static final long DATE1 = 1_000_000_000_000L;
152152

153153
/**
154154
* Size of test directory.
@@ -1759,7 +1759,7 @@ public void testIsFileNewerOlder(final long millis) throws Exception {
17591759
assertFalse(FileUtils.isFileNewer(newFile, localDatePlusDay), "New File - Newer - LocalDate plus one day");
17601760
assertFalse(FileUtils.isFileNewer(newFile, localDatePlusDay, localTime0), "New File - Newer - LocalDate plus one day,LocalTime");
17611761
assertFalse(FileUtils.isFileNewer(newFile, localDatePlusDay, offsetTime0), "New File - Newer - LocalDate plus one day,OffsetTime");
1762-
assertFalse(FileUtils.isFileNewer(invalidFile, refFile), "Invalid - Newer - File");
1762+
assertFalse(FileUtils.isFileNewer(invalidFile, refFile), "Illegal - Newer - File");
17631763
assertThrows(IllegalArgumentException.class, () -> FileUtils.isFileNewer(newFile, invalidFile));
17641764

17651765
// Test isFileOlder()
@@ -1793,7 +1793,7 @@ public void testIsFileNewerOlder(final long millis) throws Exception {
17931793
assertTrue(FileUtils.isFileOlder(newFile, localDatePlusDay, localTime0), "New File - Older - LocalDate plus one day,LocalTime");
17941794
assertTrue(FileUtils.isFileOlder(newFile, localDatePlusDay, offsetTime0), "New File - Older - LocalDate plus one day,OffsetTime");
17951795

1796-
assertFalse(FileUtils.isFileOlder(invalidFile, refFile), "Invalid - Older - File");
1796+
assertFalse(FileUtils.isFileOlder(invalidFile, refFile), "Illegal - Older - File");
17971797
assertThrows(IllegalArgumentException.class, () -> FileUtils.isFileOlder(newFile, invalidFile));
17981798

17991799
// Null File

src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ protected void testHttpInvalid(final String cT, final String bomEnc, final Strin
392392
new XmlStreamReader(is, cT, false).close();
393393
fail("It should have failed for HTTP Content-type " + cT + ", BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc);
394394
} catch (final IOException ex) {
395-
assertTrue(ex.getMessage().contains("Invalid encoding,"));
395+
assertTrue(ex.getMessage().contains("Illegal encoding,"));
396396
}
397397
}
398398
}
@@ -445,7 +445,7 @@ protected void testRawBomInvalid(final String bomEnc, final String streamEnc,
445445
fail("Expected IOException for BOM " + bomEnc + ", streamEnc " + streamEnc + " and prologEnc " + prologEnc
446446
+ ": found " + foundEnc);
447447
} catch (final IOException ex) {
448-
assertTrue(ex.getMessage().contains("Invalid encoding,"));
448+
assertTrue(ex.getMessage().contains("Illegal encoding,"));
449449
}
450450
if (xmlReader != null) {
451451
xmlReader.close();

src/test/java/org/apache/commons/io/input/XmlStreamReaderUtilitiesTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static class MockXmlStreamReader extends XmlStreamReader {
4141
private static final String HTTPMGS1 = "BOM must be NULL";
4242
private static final String HTTPMGS2 = "encoding mismatch";
4343

44-
private static final String HTTPMGS3 = "Invalid MIME";
44+
private static final String HTTPMGS3 = "Illegal MIME";
4545
private static final String APPXML = "application/xml";
4646
private static final String APPXML_UTF8 = "application/xml;charset=UTF-8";
4747
private static final String APPXML_UTF16 = "application/xml;charset=UTF-16";
@@ -100,7 +100,7 @@ private void checkHttpError(final String msgSuffix, final boolean lenient, final
100100
checkHttpEncoding("XmlStreamReaderException", lenient, httpContentType, bomEnc, xmlGuessEnc, xmlEnc, defaultEncoding);
101101
fail("Expected XmlStreamReaderException");
102102
} catch (final XmlStreamReaderException e) {
103-
assertTrue(e.getMessage().startsWith("Invalid encoding"), "Msg Start: " + e.getMessage());
103+
assertTrue(e.getMessage().startsWith("Illegal encoding"), "Msg Start: " + e.getMessage());
104104
assertTrue(e.getMessage().endsWith(msgSuffix), "Msg End: " + e.getMessage());
105105
assertEquals(bomEnc, e.getBomEncoding(), "bomEnc");
106106
assertEquals(xmlGuessEnc, e.getXmlGuessEncoding(), "xmlGuessEnc");
@@ -131,7 +131,7 @@ private void checkRawError(final String msgSuffix,
131131
checkRawEncoding("XmlStreamReaderException", bomEnc, xmlGuessEnc, xmlEnc, defaultEncoding);
132132
fail("Expected XmlStreamReaderException");
133133
} catch (final XmlStreamReaderException e) {
134-
assertTrue(e.getMessage().startsWith("Invalid encoding"), "Msg Start: " + e.getMessage());
134+
assertTrue(e.getMessage().startsWith("Illegal encoding"), "Msg Start: " + e.getMessage());
135135
assertTrue(e.getMessage().endsWith(msgSuffix), "Msg End: " + e.getMessage());
136136
assertEquals(bomEnc, e.getBomEncoding(), "bomEnc");
137137
assertEquals(xmlGuessEnc, e.getXmlGuessEncoding(), "xmlGuessEnc");

src/test/java/org/apache/commons/io/input/compatibility/XmlStreamReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@ public class XmlStreamReader extends Reader {
9898
Pattern.MULTILINE);
9999

100100
private static final MessageFormat RAW_EX_1 = new MessageFormat(
101-
"Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch");
101+
"Illegal encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding mismatch");
102102

103103
private static final MessageFormat RAW_EX_2 = new MessageFormat(
104-
"Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM");
104+
"Illegal encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown BOM");
105105

106106
private static final MessageFormat HTTP_EX_1 = new MessageFormat(
107-
"Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL");
107+
"Illegal encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], BOM must be NULL");
108108

109109
private static final MessageFormat HTTP_EX_2 = new MessageFormat(
110-
"Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch");
110+
"Illegal encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], encoding mismatch");
111111

112112
private static final MessageFormat HTTP_EX_3 = new MessageFormat(
113-
"Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Invalid MIME");
113+
"Illegal encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess [{3}] XML prolog [{4}], Illegal MIME");
114114

115115
// returns the BOM in the stream, NULL if not present,
116116
// if there was BOM the in the stream it is consumed

0 commit comments

Comments
 (0)