This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 027fa08f4 FileUtils.readLines(File, Charset) now maps a null Charset 
to the default Charset #744
027fa08f4 is described below

commit 027fa08f4269cfea0a09d31c3dd67c1667c5e8c3
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Tue May 6 08:51:37 2025 -0400

    FileUtils.readLines(File, Charset) now maps a null Charset to the
    default Charset #744
---
 src/changes/changes.xml                            |  1 +
 .../java/org/apache/commons/io/FileUtilsTest.java  | 29 +++++++++++-----------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 523767e78..ba3cb87d1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -56,6 +56,7 @@ The <action> type attribute can be add,update,fix,remove.
       <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>
       <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>
       <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>
+      <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>
       <!-- ADD -->
       <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> 
       <!-- UPDATE -->
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java 
b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index 661c41288..580e0bbd1 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -2821,10 +2821,11 @@ public void testReadFileToStringWithEncoding() throws 
Exception {
     public void testReadLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         try {
-            final String[] data = {"hello", "\u1234", "", "this is", "some 
text"};
+            final String[] data = { "hello", "\u1234", "", "this is", "some 
text" };
             TestUtils.createLineFileUtf8(file, data);
-
-            final List<String> lines = FileUtils.readLines(file, UTF_8);
+            List<String> lines = FileUtils.readLines(file, UTF_8);
+            assertEquals(Arrays.asList(data), lines);
+            lines = FileUtils.readLines(file, (Charset) null);
             assertEquals(Arrays.asList(data), lines);
         } finally {
             TestUtils.deleteFile(file);
@@ -2832,24 +2833,14 @@ public void testReadLines() throws Exception {
     }
 
     @Test
-    public void testReadLines_Errors() {
-        assertThrows(NullPointerException.class, () -> 
FileUtils.readLines(null));
-        assertThrows(IOException.class, () -> FileUtils.readLines(new 
File("non-exsistent")));
-        assertThrows(IOException.class, () -> 
FileUtils.readLines(tempDirFile));
-        assertThrows(UnsupportedCharsetException.class, () -> 
FileUtils.readLines(tempDirFile, "unsupported-charset"));
-    }
-
-    @Test
-    public void testReadLines_Defaults() throws Exception {
+    public void testReadLinesDefaults() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
         try {
-            final String[] data = {"hello", "this is", "some text"};
+            final String[] data = { "hello", "this is", "some text" };
             TestUtils.createLineFileUtf8(file, data);
-
             final List<String> lines1 = FileUtils.readLines(file);
             final List<String> lines2 = FileUtils.readLines(file, (Charset) 
null);
             final List<String> lines3 = FileUtils.readLines(file, 
Charset.defaultCharset());
-
             assertEquals(lines1, Arrays.asList(data));
             assertEquals(lines1, lines2);
             assertEquals(lines1, lines3);
@@ -2858,6 +2849,14 @@ public void testReadLines_Defaults() throws Exception {
         }
     }
 
+    @Test
+    public void testReadLines_Errors() {
+        assertThrows(NullPointerException.class, () -> 
FileUtils.readLines(null));
+        assertThrows(IOException.class, () -> FileUtils.readLines(new 
File("non-exsistent")));
+        assertThrows(IOException.class, () -> 
FileUtils.readLines(tempDirFile));
+        assertThrows(UnsupportedCharsetException.class, () -> 
FileUtils.readLines(tempDirFile, "unsupported-charset"));
+    }
+
     @Test
     @EnabledIf("isPosixFilePermissionsSupported")
     public void testReadLines_IOExceptionOnPosixFileSystem() throws Exception {

Reply via email to