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 8b56fda [IO-641] NPE in
org.apache.commons.io.IOUtils.contentEquals(Reader, Reader) when only one input
is null.
8b56fda is described below
commit 8b56fda49a913f26bbff128ac1b4e9eb3cb54cf5
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Nov 25 11:54:21 2019 -0500
[IO-641] NPE in org.apache.commons.io.IOUtils.contentEquals(Reader,
Reader) when only one input is null.
---
src/changes/changes.xml | 3 +++
src/main/java/org/apache/commons/io/IOUtils.java | 13 ++++++++-----
src/test/java/org/apache/commons/io/IOUtilsTestCase.java | 12 ++++++++++++
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index fc34f47..1623495 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -168,6 +168,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-640" dev="ggregory" type="add" due-to="Gary Gregory">
NPE in org.apache.commons.io.IOUtils.contentEquals(InputStream,
InputStream) when only one input is null.
</action>
+ <action issue="IO-641" dev="ggregory" type="add" due-to="Gary Gregory">
+ NPE in org.apache.commons.io.IOUtils.contentEquals(Reader, Reader)
when only one input is null.
+ </action>
</release>
<release version="2.6" date="2017-10-15" description="Java 7 required,
Java 9 supported.">
diff --git a/src/main/java/org/apache/commons/io/IOUtils.java
b/src/main/java/org/apache/commons/io/IOUtils.java
index ba92c2e..0fb82c3 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -698,6 +698,7 @@ public class IOUtils {
* <p>
* This method buffers the input internally using
* <code>BufferedInputStream</code> if they are not already buffered.
+ * </p>
*
* @param input1 the first stream
* @param input2 the second stream
@@ -734,6 +735,7 @@ public class IOUtils {
* <p>
* This method buffers the input internally using
* <code>BufferedReader</code> if they are not already buffered.
+ * </p>
*
* @param input1 the first reader
* @param input2 the second reader
@@ -749,9 +751,11 @@ public class IOUtils {
if (input1 == input2) {
return true;
}
-
- BufferedReader bufferedInput1 = toBufferedReader(input1);
- BufferedReader bufferedInput2 = toBufferedReader(input2);
+ if (input1 == null ^ input2 == null) {
+ return false;
+ }
+ final BufferedReader bufferedInput1 = toBufferedReader(input1);
+ final BufferedReader bufferedInput2 = toBufferedReader(input2);
int ch = bufferedInput1.read();
while (EOF != ch) {
@@ -762,8 +766,7 @@ public class IOUtils {
ch = bufferedInput1.read();
}
- final int ch2 = bufferedInput2.read();
- return ch2 == EOF;
+ return bufferedInput2.read() == EOF;
}
/**
diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
index 4ea628e..0a61982 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -264,6 +264,18 @@ public class IOUtilsTestCase {
@Test public void testContentEquals_Reader_Reader() throws Exception {
{
final StringReader input1 = new StringReader("");
+ assertTrue(IOUtils.contentEquals((Reader) null, null));
+ }
+ {
+ final StringReader input1 = new StringReader("");
+ assertFalse(IOUtils.contentEquals(null, input1));
+ }
+ {
+ final StringReader input1 = new StringReader("");
+ assertFalse(IOUtils.contentEquals(input1, null));
+ }
+ {
+ final StringReader input1 = new StringReader("");
assertTrue(IOUtils.contentEquals(input1, input1));
}
{