diff --git a/library/java/net/openid/appauth/Utils.java b/library/java/net/openid/appauth/Utils.java index 000a65b4..c78ede27 100644 --- a/library/java/net/openid/appauth/Utils.java +++ b/library/java/net/openid/appauth/Utils.java @@ -33,6 +33,10 @@ private Utils() { * Read a string from an input stream. */ public static String readInputStream(InputStream in) throws IOException { + if (in == null) { + throw new IOException("Input stream must not be null"); + } + BufferedReader br = new BufferedReader(new InputStreamReader(in)); char[] buffer = new char[INITIAL_READ_BUFFER_SIZE]; StringBuilder sb = new StringBuilder(); diff --git a/library/javatests/net/openid/appauth/UtilsTest.java b/library/javatests/net/openid/appauth/UtilsTest.java index 7328b63a..81623542 100644 --- a/library/javatests/net/openid/appauth/UtilsTest.java +++ b/library/javatests/net/openid/appauth/UtilsTest.java @@ -66,4 +66,9 @@ public void testReadInputStream() throws Exception { InputStream in = new ByteArrayInputStream(TEST_STRING.getBytes()); assertEquals(TEST_STRING, Utils.readInputStream(in)); } + + @Test(expected = IOException.class) + public void testReadInputStream_throw() throws Exception{ + Utils.readInputStream(null); + } }