Skip to content

Commit 7d41cb1

Browse files
committed
Use final
- Use 'L' for long literal - Use compact array declaration
1 parent 1db65f5 commit 7d41cb1

10 files changed

Lines changed: 16 additions & 16 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,7 @@ private static boolean setTimes(final File sourceFile, final File targetFile) {
28202820
// null guards are not needed; BasicFileAttributes.setTimes(...) is null safe
28212821
destAttrView.setTimes(srcAttr.lastModifiedTime(), srcAttr.lastAccessTime(), srcAttr.creationTime());
28222822
return true;
2823-
} catch (IOException ignored) {
2823+
} catch (final IOException ignored) {
28242824
// Fallback: Only set modified time to match source file
28252825
return targetFile.setLastModified(sourceFile.lastModified());
28262826
}
@@ -2895,7 +2895,7 @@ public static BigInteger sizeOfAsBigInteger(final File file) {
28952895
public static long sizeOfDirectory(final File directory) {
28962896
try {
28972897
requireDirectoryExists(directory, "directory");
2898-
} catch (FileNotFoundException e) {
2898+
} catch (final FileNotFoundException e) {
28992899
throw new UncheckedIOException(e);
29002900
}
29012901
return Uncheck.get(() -> PathUtils.sizeOfDirectory(directory.toPath()));
@@ -2913,7 +2913,7 @@ public static long sizeOfDirectory(final File directory) {
29132913
public static BigInteger sizeOfDirectoryAsBigInteger(final File directory) {
29142914
try {
29152915
requireDirectoryExists(directory, "directory");
2916-
} catch (FileNotFoundException e) {
2916+
} catch (final FileNotFoundException e) {
29172917
throw new UncheckedIOException(e);
29182918
}
29192919
return Uncheck.get(() -> PathUtils.sizeOfDirectoryAsBigInteger(directory.toPath()));

src/main/java/org/apache/commons/io/file/PathUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ public static boolean fileContentEquals(final Path path1, final Path path2, fina
770770
try (RandomAccessFile raf1 = RandomAccessFileMode.READ_ONLY.create(path1.toRealPath(linkOptions));
771771
RandomAccessFile raf2 = RandomAccessFileMode.READ_ONLY.create(path2.toRealPath(linkOptions))) {
772772
return RandomAccessFiles.contentEquals(raf1, raf2);
773-
} catch (UnsupportedOperationException e) {
773+
} catch (final UnsupportedOperationException e) {
774774
// Slower:
775775
// Handle
776776
// java.lang.UnsupportedOperationException
@@ -877,7 +877,7 @@ public static DosFileAttributeView getDosFileAttributeView(final Path path, fina
877877
* @see Path#getFileName()
878878
* @since 2.16.0
879879
*/
880-
public static <R> R getFileName(final Path path, Function<Path, R> function) {
880+
public static <R> R getFileName(final Path path, final Function<Path, R> function) {
881881
final Path fileName = path != null ? path.getFileName() : null;
882882
return fileName != null ? function.apply(fileName) : null;
883883
}

src/main/java/org/apache/commons/io/filefilter/AbstractFileFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void append(final Object[] array, final StringBuilder buffer) {
120120
FileVisitResult get(final IOSupplier<FileVisitResult> supplier) {
121121
try {
122122
return supplier.get();
123-
} catch (IOException e) {
123+
} catch (final IOException e) {
124124
return handle(e);
125125
}
126126
}

src/main/java/org/apache/commons/io/function/IOStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public boolean hasNext() {
9797
public T next() throws NoSuchElementException {
9898
try {
9999
return t = t == IOStreams.NONE ? seed : f.apply(t);
100-
} catch (IOException e) {
100+
} catch (final IOException e) {
101101
final NoSuchElementException nsee = new NoSuchElementException();
102102
nsee.initCause(e);
103103
throw nsee;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private CharSequenceInputStream(final CharSequence cs, final int bufferSize, fin
182182
this.bBufMark = NO_MARK;
183183
try {
184184
fillBuffer();
185-
} catch (CharacterCodingException ex) {
185+
} catch (final CharacterCodingException ex) {
186186
// Reset everything without filling the buffer
187187
// so the same exception can be thrown again later.
188188
this.bBuf.clear();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public UnsynchronizedByteArrayInputStream(final byte[] data, final int offset, f
219219
this.markedOffset = minPosLen(data, offset);
220220
}
221221

222-
private UnsynchronizedByteArrayInputStream(byte[] data, int eod, int offset, int markedOffset) {
222+
private UnsynchronizedByteArrayInputStream(final byte[] data, final int eod, final int offset, final int markedOffset) {
223223
this.data = Objects.requireNonNull(data, "data");
224224
this.eod = eod;
225225
this.offset = offset;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public void testEOFException() {
4545

4646
@Test
4747
public void testInvalidOffset() throws IOException {
48-
final byte[] bytes = new byte[0];
48+
final byte[] bytes = {};
4949

5050
assertThrows(IllegalArgumentException.class, () -> EndianUtils.readSwappedInteger(bytes, 0));
5151
assertThrows(IllegalArgumentException.class, () -> EndianUtils.readSwappedLong(bytes, 0));
5252
assertThrows(IllegalArgumentException.class, () -> EndianUtils.readSwappedShort(bytes, 0));
5353
assertThrows(IllegalArgumentException.class, () -> EndianUtils.readSwappedUnsignedInteger(bytes, 0));
5454
assertThrows(IllegalArgumentException.class, () -> EndianUtils.readSwappedUnsignedShort(bytes, 0));
5555
assertThrows(IllegalArgumentException.class, () -> EndianUtils.writeSwappedInteger(bytes, 0, 0));
56-
assertThrows(IllegalArgumentException.class, () -> EndianUtils.writeSwappedLong(bytes, 0, 0l));
56+
assertThrows(IllegalArgumentException.class, () -> EndianUtils.writeSwappedLong(bytes, 0, 0L));
5757
assertThrows(IllegalArgumentException.class, () -> EndianUtils.writeSwappedShort(bytes, 0, (short) 0));
5858
}
5959

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ private void testMarkResetMultiByteChars(final String csName) throws IOException
352352
final String sequenceEnglish = "Test Sequence";
353353
final String sequenceCJK = "\u4e01\u4f23\u5045\u5167\u5289\u53ab"; // Kanji text
354354
final String[] sequences = {sequenceEnglish, sequenceCJK};
355-
for (String testSequence : sequences) {
355+
for (final String testSequence : sequences) {
356356
final CharsetEncoder charsetEncoder = Charset.forName(csName).newEncoder();
357357
final ByteBuffer byteBuffer = ByteBuffer.allocate(testSequence.length() * 3);
358358
final CharBuffer charBuffer = CharBuffer.wrap(testSequence);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
3636
private UnsynchronizedByteArrayInputStream newStream(final byte[] buffer) {
3737
try {
3838
return UnsynchronizedByteArrayInputStream.builder().setByteArray(buffer).get();
39-
} catch (IOException e) {
39+
} catch (final IOException e) {
4040
fail("Should never happen because no conversion is needed.", e);
4141
return null;
4242
}
@@ -45,7 +45,7 @@ private UnsynchronizedByteArrayInputStream newStream(final byte[] buffer) {
4545
private UnsynchronizedByteArrayInputStream newStream(final byte[] buffer, final int offset) {
4646
try {
4747
return UnsynchronizedByteArrayInputStream.builder().setByteArray(buffer).setOffset(offset).get();
48-
} catch (IOException e) {
48+
} catch (final IOException e) {
4949
fail("Should never happen because no conversion is needed.", e);
5050
return null;
5151
}
@@ -54,7 +54,7 @@ private UnsynchronizedByteArrayInputStream newStream(final byte[] buffer, final
5454
private UnsynchronizedByteArrayInputStream newStream(final byte[] buffer, final int offset, final int length) {
5555
try {
5656
return UnsynchronizedByteArrayInputStream.builder().setByteArray(buffer).setOffset(offset).setLength(length).get();
57-
} catch (IOException e) {
57+
} catch (final IOException e) {
5858
fail("Should never happen because no conversion is needed.", e);
5959
return null;
6060
}

src/test/java/org/apache/commons/io/jmh/PathUtilsContentEqualsBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class PathUtilsContentEqualsBenchmark {
7272
Arrays.fill(bytes1, (byte) 1);
7373
Files.write(bigFile1, bytes1);
7474
Files.copy(bigFile1, bigFile2, StandardCopyOption.REPLACE_EXISTING);
75-
} catch (IOException e) {
75+
} catch (final IOException e) {
7676
throw new UncheckedIOException(e);
7777
}
7878
}

0 commit comments

Comments
 (0)