From 7a903a2e7c102810028f2d1b1757f8b6db1124ac Mon Sep 17 00:00:00 2001 From: Thomas Rebouillon Date: Wed, 26 Sep 2018 09:51:10 +0200 Subject: [PATCH 1/2] Issue #402: fixes NPE in case input stream is null --- library/java/net/openid/appauth/Utils.java | 4 ++++ library/javatests/net/openid/appauth/UtilsTest.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/library/java/net/openid/appauth/Utils.java b/library/java/net/openid/appauth/Utils.java index 000a65b4..736b7498 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); + } } From f4cdab0f62acb74919c219ef93c841caaa2d8ded Mon Sep 17 00:00:00 2001 From: Iain McGinniss Date: Mon, 1 Oct 2018 16:55:34 -0700 Subject: [PATCH 2/2] Fix double-space --- library/java/net/openid/appauth/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/java/net/openid/appauth/Utils.java b/library/java/net/openid/appauth/Utils.java index 736b7498..c78ede27 100644 --- a/library/java/net/openid/appauth/Utils.java +++ b/library/java/net/openid/appauth/Utils.java @@ -34,7 +34,7 @@ private Utils() { */ public static String readInputStream(InputStream in) throws IOException { if (in == null) { - throw new IOException("Input stream must not be null"); + throw new IOException("Input stream must not be null"); } BufferedReader br = new BufferedReader(new InputStreamReader(in));