Skip to content

Commit 027fa08

Browse files
committed
FileUtils.readLines(File, Charset) now maps a null Charset to the
default Charset #744
1 parent a894c74 commit 027fa08

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The <action> type attribute can be add,update,fix,remove.
5656
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.getWriter(Charset) now maps a null Charset to the default Charset.</action>
5757
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.AbstractRandomAccessFileOrigin.getWriter(Charset) now maps a null Charset to the default Charset.</action>
5858
<action dev="ggregory" type="fix" due-to="Gary Gregory">org.apache.commons.io.build.AbstractOrigin.OutputStreamOrigin.getWriter(Charset) now maps a null Charset to the default Charset.</action>
59+
<action dev="ggregory" type="fix" due-to="Ryan Kurtz, Gary Gregory">FileUtils.readLines(File, Charset) now maps a null Charset to the default Charset #744.</action>
5960
<!-- ADD -->
6061
<action dev="ggregory" type="add" issue="IO-875" due-to="Pierre Baumard, Gary Gregory">Add and use org.apache.commons.io.file.CountingPathVisitor.accept(Path, BasicFileAttributes) #743.</action>
6162
<!-- UPDATE -->

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,35 +2821,26 @@ public void testReadFileToStringWithEncoding() throws Exception {
28212821
public void testReadLines() throws Exception {
28222822
final File file = TestUtils.newFile(tempDirFile, "lines.txt");
28232823
try {
2824-
final String[] data = {"hello", "\u1234", "", "this is", "some text"};
2824+
final String[] data = { "hello", "\u1234", "", "this is", "some text" };
28252825
TestUtils.createLineFileUtf8(file, data);
2826-
2827-
final List<String> lines = FileUtils.readLines(file, UTF_8);
2826+
List<String> lines = FileUtils.readLines(file, UTF_8);
2827+
assertEquals(Arrays.asList(data), lines);
2828+
lines = FileUtils.readLines(file, (Charset) null);
28282829
assertEquals(Arrays.asList(data), lines);
28292830
} finally {
28302831
TestUtils.deleteFile(file);
28312832
}
28322833
}
28332834

28342835
@Test
2835-
public void testReadLines_Errors() {
2836-
assertThrows(NullPointerException.class, () -> FileUtils.readLines(null));
2837-
assertThrows(IOException.class, () -> FileUtils.readLines(new File("non-exsistent")));
2838-
assertThrows(IOException.class, () -> FileUtils.readLines(tempDirFile));
2839-
assertThrows(UnsupportedCharsetException.class, () -> FileUtils.readLines(tempDirFile, "unsupported-charset"));
2840-
}
2841-
2842-
@Test
2843-
public void testReadLines_Defaults() throws Exception {
2836+
public void testReadLinesDefaults() throws Exception {
28442837
final File file = TestUtils.newFile(tempDirFile, "lines.txt");
28452838
try {
2846-
final String[] data = {"hello", "this is", "some text"};
2839+
final String[] data = { "hello", "this is", "some text" };
28472840
TestUtils.createLineFileUtf8(file, data);
2848-
28492841
final List<String> lines1 = FileUtils.readLines(file);
28502842
final List<String> lines2 = FileUtils.readLines(file, (Charset) null);
28512843
final List<String> lines3 = FileUtils.readLines(file, Charset.defaultCharset());
2852-
28532844
assertEquals(lines1, Arrays.asList(data));
28542845
assertEquals(lines1, lines2);
28552846
assertEquals(lines1, lines3);
@@ -2858,6 +2849,14 @@ public void testReadLines_Defaults() throws Exception {
28582849
}
28592850
}
28602851

2852+
@Test
2853+
public void testReadLines_Errors() {
2854+
assertThrows(NullPointerException.class, () -> FileUtils.readLines(null));
2855+
assertThrows(IOException.class, () -> FileUtils.readLines(new File("non-exsistent")));
2856+
assertThrows(IOException.class, () -> FileUtils.readLines(tempDirFile));
2857+
assertThrows(UnsupportedCharsetException.class, () -> FileUtils.readLines(tempDirFile, "unsupported-charset"));
2858+
}
2859+
28612860
@Test
28622861
@EnabledIf("isPosixFilePermissionsSupported")
28632862
public void testReadLines_IOExceptionOnPosixFileSystem() throws Exception {

0 commit comments

Comments
 (0)