You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by rm...@apache.org on 2019/09/28 17:22:11 UTC

[johnzon] branch master updated: adding NothingToRead exception

This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/johnzon.git


The following commit(s) were added to refs/heads/master by this push:
     new e8d79d2  adding NothingToRead exception
e8d79d2 is described below

commit e8d79d2ceddd1d589679cce34b7a6ff7703e776b
Author: Romain Manni-Bucau <rm...@apache.org>
AuthorDate: Sat Sep 28 19:22:06 2019 +0200

    adding NothingToRead exception
---
 .../src/main/java/org/apache/johnzon/core/JsonReaderImpl.java     | 8 +++++++-
 .../src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java | 8 ++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonReaderImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonReaderImpl.java
index 71bd0e1..24de161 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonReaderImpl.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonReaderImpl.java
@@ -72,7 +72,7 @@ public class JsonReaderImpl implements JsonReader {
         checkClosed();
 
         if (!parser.hasNext()) {
-            throw new IllegalStateException("Nothing to read");
+            throw new NothingToRead();
         }
 
 
@@ -282,4 +282,10 @@ public class JsonReaderImpl implements JsonReader {
         }
 
     }
+
+    public static class NothingToRead extends IllegalStateException {
+        public NothingToRead() {
+            super("Nothing to read");
+        }
+    }
 }
diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java
index e41cdbe..becdf5f 100644
--- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.johnzon.core;
 
+import static java.util.Collections.emptyMap;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -425,6 +426,13 @@ public class JsonReaderImplTest {
         reader.close();
     }
 
+    @Test(expected = JsonReaderImpl.NothingToRead.class)
+    public void emptyStream() {
+        Json.createReaderFactory(emptyMap())
+                .createReader(new ByteArrayInputStream(new byte[0]), utf8Charset)
+                .readObject();
+    }
+
     @Test(expected = IllegalArgumentException.class)
     public void emptyZeroCharBuffersize() {
         final JsonReader reader = Json.createReaderFactory(new HashMap<String, Object>() {