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 2014/06/29 16:57:24 UTC

git commit: FLEECE-3 JsonStreamParser.isIntegralNumber() does not throw IllegalStateException, patch from Hendrik Saly

Repository: incubator-fleece
Updated Branches:
  refs/heads/master 16204fa73 -> 06002755d


FLEECE-3 JsonStreamParser.isIntegralNumber() does not throw IllegalStateException, patch from Hendrik Saly


Project: http://git-wip-us.apache.org/repos/asf/incubator-fleece/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fleece/commit/06002755
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fleece/tree/06002755
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fleece/diff/06002755

Branch: refs/heads/master
Commit: 06002755daf2786fae62e4a13fa18c22ffcbde88
Parents: 16204fa
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Sun Jun 29 16:57:04 2014 +0200
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Sun Jun 29 16:57:04 2014 +0200

----------------------------------------------------------------------
 .../org/apache/fleece/core/JsonStreamParser.java     | 15 +++++++++++----
 .../java/org/apache/fleece/core/JsonParserTest.java  | 12 ++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fleece/blob/06002755/fleece-core/src/main/java/org/apache/fleece/core/JsonStreamParser.java
----------------------------------------------------------------------
diff --git a/fleece-core/src/main/java/org/apache/fleece/core/JsonStreamParser.java b/fleece-core/src/main/java/org/apache/fleece/core/JsonStreamParser.java
index ffcb870..4c8914b 100644
--- a/fleece-core/src/main/java/org/apache/fleece/core/JsonStreamParser.java
+++ b/fleece-core/src/main/java/org/apache/fleece/core/JsonStreamParser.java
@@ -107,6 +107,7 @@ public class JsonStreamParser implements JsonChars, EscapedStringAwareJsonParser
                                 builder.append(current);
                             } else {
                                 builder.append(asEscapedChar(current));
+                                escaped = false;
                             }
                         }
                         escapedValue = currentValue;
@@ -187,10 +188,10 @@ public class JsonStreamParser implements JsonChars, EscapedStringAwareJsonParser
     }
 
     private boolean isNumber() {
-        return isNumber(loadedChars[currentBufferIdx]) || loadedChars[currentBufferIdx] == DOT || loadedChars[currentBufferIdx] == MINUS || loadedChars[currentBufferIdx] == PLUS || loadedChars[currentBufferIdx] == EXP_LOWERCASE || loadedChars[currentBufferIdx] == EXP_UPPERCASE;
+        return isAsciiDigit(loadedChars[currentBufferIdx]) || loadedChars[currentBufferIdx] == DOT || loadedChars[currentBufferIdx] == MINUS || loadedChars[currentBufferIdx] == PLUS || loadedChars[currentBufferIdx] == EXP_LOWERCASE || loadedChars[currentBufferIdx] == EXP_UPPERCASE;
     }
 
-    private static boolean isNumber(final char value) {
+    private static boolean isAsciiDigit(final char value) {
         return value >= ZERO && value <= NINE;
     }
 
@@ -276,16 +277,22 @@ public class JsonStreamParser implements JsonChars, EscapedStringAwareJsonParser
         if (lastEvent == Event.KEY_NAME || lastEvent == Event.VALUE_STRING || lastEvent == Event.VALUE_NUMBER) {
             return currentValue;
         }
-        throw new IllegalStateException(event + " doesnt support getString()");
+        throw new IllegalStateException(event + " doesn't support getString()");
     }
 
     @Override
     public boolean isIntegralNumber() {
+        
+        if (lastEvent != Event.VALUE_NUMBER) {
+            throw new IllegalStateException(event + " doesn't support isIntegralNumber()");
+        }
+        
         for (int i = 0; i < currentValue.length(); i++) {
-            if (!isNumber(currentValue.charAt(i))) {
+            if (!isAsciiDigit(currentValue.charAt(i))) {
                 return false;
             }
         }
+        
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-fleece/blob/06002755/fleece-core/src/test/java/org/apache/fleece/core/JsonParserTest.java
----------------------------------------------------------------------
diff --git a/fleece-core/src/test/java/org/apache/fleece/core/JsonParserTest.java b/fleece-core/src/test/java/org/apache/fleece/core/JsonParserTest.java
index 6e4727f..31f1b93 100644
--- a/fleece-core/src/test/java/org/apache/fleece/core/JsonParserTest.java
+++ b/fleece-core/src/test/java/org/apache/fleece/core/JsonParserTest.java
@@ -347,6 +347,18 @@ public class JsonParserTest {
         }
         parser.close();
     }
+    
+    @Test(expected=IllegalStateException.class)
+    public void isIntegralThrowsISE() {
+        final JsonParser parser = Json.createParser(Thread.currentThread().getContextClassLoader().getResourceAsStream("json/bigdecimal.json"));
+        assertNotNull(parser);
+        assertTrue(parser.hasNext());
+        final JsonParser.Event event = parser.next();
+        assertNotNull(event);
+        assertEquals(JsonParser.Event.START_OBJECT, event);
+        assertFalse(parser.isIntegralNumber());
+            
+    }
 
     @Test
     public void escaping() {