NPE in org.apache.commons.io.IOUtils.contentEquals(Reader,
Reader) when only one input is null.
MODIFY
src/changes/changes.xml
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.">

MODIFY
src/main/java/org/apache/commons/io/IOUtils.java
src/main/java/org/apache/commons/io/IOUtils.java
@@ -698,6 +698,7 @@ public static void closeQuietly(final Writer output) {
* <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 static boolean contentEquals(final InputStream input1, final InputStream
* <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 static boolean contentEquals(final Reader input1, final Reader input2)
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 static boolean contentEquals(final Reader input1, final Reader input2)
ch = bufferedInput1.read();
}
- final int ch2 = bufferedInput2.read();
- return ch2 == EOF;
+ return bufferedInput2.read() == EOF;
}
/**

MODIFY
src/test/java/org/apache/commons/io/IOUtilsTestCase.java
src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -262,6 +262,18 @@ public synchronized void close() throws IOException {
}
@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));

[IO-641] NPE in org.apache.commons.io.IOUtils.contentEquals(Reader,
Reader) when only one input is null.