dropping unnecessary casts and conversions
MODIFY
src/main/java/org/apache/commons/io/IOUtils.java
src/main/java/org/apache/commons/io/IOUtils.java
@@ -463,7 +463,7 @@ public static void close(final URLConnection conn) {
* @see Throwable#addSuppressed(java.lang.Throwable)
*/
public static void closeQuietly(final Closeable closeable) {
- closeQuietly(closeable, (Consumer<IOException>) null);
+ closeQuietly(closeable, null);
}
/**

MODIFY
src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
@@ -1151,32 +1151,32 @@ public void testIsExtensionCollection() {
assertFalse(FilenameUtils.isExtension(null, (Collection<String>) null));
assertFalse(FilenameUtils.isExtension("file.txt", (Collection<String>) null));
assertTrue(FilenameUtils.isExtension("file", (Collection<String>) null));
- assertFalse(FilenameUtils.isExtension("file.txt", new ArrayList<String>()));
+ assertFalse(FilenameUtils.isExtension("file.txt", new ArrayList<>()));
assertTrue(FilenameUtils.isExtension("file.txt", new ArrayList<>(Arrays.asList("txt"))));
assertFalse(FilenameUtils.isExtension("file.txt", new ArrayList<>(Arrays.asList("rtf"))));
assertTrue(FilenameUtils.isExtension("file", new ArrayList<>(Arrays.asList("rtf", ""))));
assertTrue(FilenameUtils.isExtension("file.txt", new ArrayList<>(Arrays.asList("rtf", "txt"))));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", (Collection<String>) null));
- assertFalse(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<String>()));
+ assertFalse(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<>()));
assertTrue(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<>(Arrays.asList("txt"))));
assertFalse(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<>(Arrays.asList("rtf"))));
assertTrue(FilenameUtils.isExtension("a/b/file.txt", new ArrayList<>(Arrays.asList("rtf", "txt"))));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", (Collection<String>) null));
- assertFalse(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<String>()));
+ assertFalse(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<>()));
assertTrue(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<>(Arrays.asList("txt"))));
assertFalse(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<>(Arrays.asList("rtf"))));
assertTrue(FilenameUtils.isExtension("a.b/file.txt", new ArrayList<>(Arrays.asList("rtf", "txt"))));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", (Collection<String>) null));
- assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<String>()));
+ assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<>()));
assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<>(Arrays.asList("txt"))));
assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<>(Arrays.asList("rtf"))));
assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", new ArrayList<>(Arrays.asList("rtf", "txt"))));
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", (Collection<String>) null));
- assertFalse(FilenameUtils.isExtension("a.b\\file.txt", new ArrayList<String>()));
+ assertFalse(FilenameUtils.isExtension("a.b\\file.txt", new ArrayList<>()));
assertTrue(FilenameUtils.isExtension("a.b\\file.txt", new ArrayList<>(Arrays.asList("txt"))));
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", new ArrayList<>(Arrays.asList("rtf"))));
assertTrue(FilenameUtils.isExtension("a.b\\file.txt", new ArrayList<>(Arrays.asList("rtf", "txt"))));

MODIFY
src/test/java/org/apache/commons/io/IOUtilsCopyTestCase.java
src/test/java/org/apache/commons/io/IOUtilsCopyTestCase.java
@@ -275,7 +275,7 @@ public void testCopy_readerToAppendable_nullIn() {
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final OutputStream out = new ThrowOnFlushAndCloseOutputStream(baout, true, true);
final Appendable writer = new OutputStreamWriter(out, StandardCharsets.US_ASCII);
- assertThrows(NullPointerException.class, () -> IOUtils.copy((Reader) null, writer));
+ assertThrows(NullPointerException.class, () -> IOUtils.copy(null, writer));
}
@SuppressWarnings("resource") // 'in' is deliberately not closed

MODIFY
src/test/java/org/apache/commons/io/IOUtilsTestCase.java
src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -392,7 +392,7 @@ public void testCloseQuietly_AllCloseableIOException() {
@Test
public void testCloseQuietly_CloseableIOException() {
assertDoesNotThrow(() -> {
- IOUtils.closeQuietly((Closeable) () -> {
+ IOUtils.closeQuietly(() -> {
throw new IOException();
});
});
@@ -598,7 +598,7 @@ public void testContentEquals_Reader_Reader() throws Exception {
@Test
public void testContentEqualsIgnoreEOL() throws Exception {
{
- assertTrue(IOUtils.contentEqualsIgnoreEOL((Reader) null, null));
+ assertTrue(IOUtils.contentEqualsIgnoreEOL(null, null));
}
{
final Reader input1 = new CharArrayReader("".toCharArray());

MODIFY
src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java
src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java
@@ -312,7 +312,7 @@ public void testAnd2() {
assertFiltering(new AndFileFilter(filters), new File("test"), false);
assertFiltering(new AndFileFilter(), new File("test"), false);
- assertThrows(NullPointerException.class, () -> new AndFileFilter(falseFilter, (IOFileFilter) null));
+ assertThrows(NullPointerException.class, () -> new AndFileFilter(falseFilter, null));
assertThrows(NullPointerException.class, () -> new AndFileFilter(null, falseFilter));
assertThrows(NullPointerException.class, () -> new AndFileFilter((List<IOFileFilter>) null));
}
@@ -790,7 +790,7 @@ public void testFilterList_fromArray() throws Exception {
@Test
public void testFilterListNullParameters() {
try {
- FileFilterUtils.filterList(null, Collections.<File>emptyList());
+ FileFilterUtils.filterList(null, Collections.emptyList());
fail();
} catch (final IllegalArgumentException iae) {
// Test passes, exception thrown for null filter
@@ -798,7 +798,7 @@ public void testFilterListNullParameters() {
final IOFileFilter filter = FileFilterUtils.trueFileFilter();
try {
- FileFilterUtils.filterList(filter, Collections.singletonList((File) null));
+ FileFilterUtils.filterList(filter, Collections.singletonList(null));
} catch (final IllegalArgumentException iae) {
// Test passes, exception thrown for list containing null
}
@@ -870,7 +870,7 @@ public void testFilterSet_fromArray() throws Exception {
@Test
public void testFilterSetNullParameters() {
try {
- FileFilterUtils.filterSet(null, Collections.<File>emptySet());
+ FileFilterUtils.filterSet(null, Collections.emptySet());
fail();
} catch (final IllegalArgumentException iae) {
// Test passes, exception thrown for null filter
@@ -878,7 +878,7 @@ public void testFilterSetNullParameters() {
final IOFileFilter filter = FileFilterUtils.trueFileFilter();
try {
- FileFilterUtils.filterSet(filter, new HashSet<>(Collections.singletonList((File) null)));
+ FileFilterUtils.filterSet(filter, new HashSet<>(Collections.singletonList(null)));
} catch (final IllegalArgumentException iae) {
// Test passes, exception thrown for set containing null
}
@@ -1355,7 +1355,7 @@ public void testOr() {
assertFalse(orFilter.accept(testFile.getParentFile(), testFile.getName()));
assertEquals(FileVisitResult.TERMINATE, orFilter.accept(testPath, null));
- assertThrows(NullPointerException.class, () -> new OrFileFilter(falseFilter, (IOFileFilter) null));
+ assertThrows(NullPointerException.class, () -> new OrFileFilter(falseFilter, null));
}
@Test

MODIFY
src/test/java/org/apache/commons/io/input/CharacterSetFilterReaderTest.java
src/test/java/org/apache/commons/io/input/CharacterSetFilterReaderTest.java
@Test
public void testInputSize0FilterSize0() throws IOException {
final StringReader input = new StringReader("");
- try (CharacterSetFilterReader reader = new CharacterSetFilterReader(input, new HashSet<Integer>(0))) {
+ try (CharacterSetFilterReader reader = new CharacterSetFilterReader(input, new HashSet<>(0))) {
assertEquals(-1, reader.read());
}
}

MODIFY
src/test/java/org/apache/commons/io/input/TailerTest.java
src/test/java/org/apache/commons/io/input/TailerTest.java
@@ -435,7 +435,7 @@ public void testIO335() throws Exception { // test CR behavior
private static class TestTailerListener extends TailerListenerAdapter {
// Must be synchronized because it is written by one thread and read by another
- private final List<String> lines = Collections.synchronizedList(new ArrayList<String>());
+ private final List<String> lines = Collections.synchronizedList(new ArrayList<>());
volatile Exception exception;

MODIFY
src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java
src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java
@@ -54,13 +54,13 @@ public void setUp() throws Exception {
@Test
public void testReadNothing() throws Exception {
- assertEquals("", new String(output.toString(ASCII)));
+ assertEquals("", output.toString(ASCII));
}
@Test
public void testReadOneByte() throws Exception {
assertEquals('a', tee.read());
- assertEquals("a", new String(output.toString(ASCII)));
+ assertEquals("a", output.toString(ASCII));
}
@Test
@@ -69,7 +69,7 @@ public void testReadEverything() throws Exception {
assertEquals('b', tee.read());
assertEquals('c', tee.read());
assertEquals(-1, tee.read());
- assertEquals("abc", new String(output.toString(ASCII)));
+ assertEquals("abc", output.toString(ASCII));
}
@Test
@@ -80,7 +80,7 @@ public void testReadToArray() throws Exception {
assertEquals('b', buffer[1]);
assertEquals('c', buffer[2]);
assertEquals(-1, tee.read(buffer));
- assertEquals("abc", new String(output.toString(ASCII)));
+ assertEquals("abc", output.toString(ASCII));
}
@Test
@@ -91,7 +91,7 @@ public void testReadToArrayWithOffset() throws Exception {
assertEquals('b', buffer[5]);
assertEquals('c', buffer[6]);
assertEquals(-1, tee.read(buffer, 4, 4));
- assertEquals("abc", new String(output.toString(ASCII)));
+ assertEquals("abc", output.toString(ASCII));
}
@Test
@@ -100,7 +100,7 @@ public void testSkip() throws Exception {
assertEquals(1, tee.skip(1));
assertEquals('c', tee.read());
assertEquals(-1, tee.read());
- assertEquals("ac", new String(output.toString(ASCII)));
+ assertEquals("ac", output.toString(ASCII));
}
@Test
@@ -112,7 +112,7 @@ public void testMarkReset() throws Exception {
assertEquals('b', tee.read());
assertEquals('c', tee.read());
assertEquals(-1, tee.read());
- assertEquals("abbc", new String(output.toString(ASCII)));
+ assertEquals("abbc", output.toString(ASCII));
}
/**

IO-746: dropping unnecessary casts and conversions (#267)

Signed-off-by: Davide Angelocola <davide.angelocola@gmail.com>