Skip to content

Commit c936be4

Browse files
author
Gary Gregory
committed
[IO-642] NPE in
org.apache.commons.io.IOUtils.contentEqualsIgnoreEOL(Reader, Reader) when only one input is null.
1 parent 8b56fda commit c936be4

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/changes/changes.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,13 @@ The <action> type attribute can be add,update,fix,remove.
167167
</action>
168168
<action issue="IO-640" dev="ggregory" type="add" due-to="Gary Gregory">
169169
NPE in org.apache.commons.io.IOUtils.contentEquals(InputStream, InputStream) when only one input is null.
170-
</action>
170+
</action>"src/changes/changes.xml"
171171
<action issue="IO-641" dev="ggregory" type="add" due-to="Gary Gregory">
172172
NPE in org.apache.commons.io.IOUtils.contentEquals(Reader, Reader) when only one input is null.
173173
</action>
174+
<action issue="IO-642" dev="ggregory" type="add" due-to="Gary Gregory">
175+
NPE in org.apache.commons.io.IOUtils.contentEqualsIgnoreEOL(Reader, Reader) when only one input is null.
176+
</action>
174177
</release>
175178

176179
<release version="2.6" date="2017-10-15" description="Java 7 required, Java 9 supported.">

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,9 @@ public static boolean contentEqualsIgnoreEOL(final Reader input1, final Reader i
789789
if (input1 == input2) {
790790
return true;
791791
}
792+
if (input1 == null ^ input2 == null) {
793+
return false;
794+
}
792795
final BufferedReader br1 = toBufferedReader(input1);
793796
final BufferedReader br2 = toBufferedReader(input2);
794797

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,18 @@ public synchronized void close() throws IOException {
290290
}
291291

292292
@Test public void testContentEqualsIgnoreEOL() throws Exception {
293+
{
294+
final Reader input1 = new CharArrayReader("".toCharArray());
295+
assertTrue(IOUtils.contentEqualsIgnoreEOL((Reader) null, null));
296+
}
297+
{
298+
final Reader input1 = new CharArrayReader("".toCharArray());
299+
assertFalse(IOUtils.contentEqualsIgnoreEOL(null, input1));
300+
}
301+
{
302+
final Reader input1 = new CharArrayReader("".toCharArray());
303+
assertFalse(IOUtils.contentEqualsIgnoreEOL(input1, null));
304+
}
293305
{
294306
final Reader input1 = new CharArrayReader("".toCharArray());
295307
assertTrue(IOUtils.contentEqualsIgnoreEOL(input1, input1));

0 commit comments

Comments
 (0)