Changeset 11320 in josm


Ignore:
Timestamp:
2016-11-26T23:45:05+01:00 (8 years ago)
Author:
wiktorn
Message:

Better handle of null in readBytesFromStream.

See: #14033

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r11319 r11320  
    13661366     *
    13671367     * @param stream input stream
    1368      * @return byte array of data in input stream
     1368     * @return byte array of data in input stream or null if stream is null
    13691369     * @throws IOException if any I/O error occurs
    13701370     */
    13711371    public static byte[] readBytesFromStream(InputStream stream) throws IOException {
     1372        if (stream == null) {
     1373            return null;
     1374        }
    13721375        try {
    13731376            ByteArrayOutputStream bout = new ByteArrayOutputStream(stream.available());
  • trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java

    r11241 r11320  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNull;
    56
     7import java.io.IOException;
    68import java.util.Arrays;
    79import java.util.Collections;
     
    162164        assertEquals("<ul></ul>", Utils.joinAsHtmlUnorderedList(Collections.emptyList()));
    163165    }
     166
     167    /**
     168     * Tests if readBytesFromStream handles null streams (might happen when there is no data on error stream)
     169     * @throws IOException
     170     *
     171     */
     172    @Test
     173    public void testNullStreamForReadBytesFromStream() throws IOException {
     174        assertNull("Null on null stream", Utils.readBytesFromStream(null));
     175    }
     176
    164177}
Note: See TracChangeset for help on using the changeset viewer.