[Git][java-team/jackson-core][upstream] New upstream version 2.9.9

Mechtilde Stehmann gitlab at salsa.debian.org
Sun Sep 15 12:39:55 BST 2019



Mechtilde Stehmann pushed to branch upstream at Debian Java Maintainers / jackson-core


Commits:
5f14fbd7 by Mechtilde at 2019-09-10T15:44:44Z
New upstream version 2.9.9
- - - - -


15 changed files:

- pom.xml
- release-notes/CREDITS-2.x
- release-notes/VERSION-2.x
- src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java
- src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java
- src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java
- src/test/java/com/fasterxml/jackson/core/json/TestRootValues.java
- + src/test/java/com/fasterxml/jackson/core/json/async/AsyncLocationTest.java
- src/test/java/com/fasterxml/jackson/core/main/TestGeneratorClosing.java
- src/test/java/com/fasterxml/jackson/core/read/JsonParserTest.java
- src/test/java/com/fasterxml/jackson/core/read/NonStandardParserFeaturesTest.java
- + src/test/java/com/fasterxml/jackson/core/read/NonStandardUnquotedNamesTest.java
- + src/test/java/com/fasterxml/jackson/core/testsupport/ByteOutputStreamForTesting.java
- + src/test/java/com/fasterxml/jackson/core/testsupport/StringWriterForTesting.java
- + src/test/java/com/fasterxml/jackson/failing/LocationOffsets533Test.java


Changes:

=====================================
pom.xml
=====================================
@@ -4,13 +4,13 @@
     <groupId>com.fasterxml.jackson</groupId>
     <!-- For 2.9.2 and beyond, new parent pom; extends jackson-bom -->
     <artifactId>jackson-base</artifactId>
-    <version>2.9.8</version>
+    <version>2.9.9</version>
   </parent>
 
   <groupId>com.fasterxml.jackson.core</groupId>
   <artifactId>jackson-core</artifactId>
   <name>Jackson-core</name>
-  <version>2.9.8</version>
+  <version>2.9.9</version>
   <packaging>bundle</packaging>
   <description>Core Jackson processing abstractions (aka Streaming API), implementation for JSON</description>
   <inceptionYear>2008</inceptionYear>
@@ -20,7 +20,7 @@
     <connection>scm:git:git at github.com:FasterXML/jackson-core.git</connection>
     <developerConnection>scm:git:git at github.com:FasterXML/jackson-core.git</developerConnection>
     <url>http://github.com/FasterXML/jackson-core</url>    
-    <tag>jackson-core-2.9.8</tag>
+    <tag>jackson-core-2.9.9</tag>
   </scm>
 
   <properties>


=====================================
release-notes/CREDITS-2.x
=====================================
@@ -155,4 +155,11 @@ Doug Roper (htmldoug at github)
   * Suggested #463: Ensure that `skipChildren()` of non-blocking `JsonParser` will throw
     exception if not enough input
   (2.9.6)
- 
+
+Alexander Eyers-Taylor (aeyerstaylor at github)
+  * Reported #510: Fix ArrayIndexOutofBoundsException found by LGTM.com
+  (2.9.9)
+
+Henrik Gustafsson (gsson at github)
+  * Reported #516: _inputPtr off-by-one in UTF8StreamJsonParser._parseNumber2()
+  (2.9.9)


=====================================
release-notes/VERSION-2.x
=====================================
@@ -14,10 +14,19 @@ JSON library.
 === Releases ===
 ------------------------------------------------------------------------
 
+2.9.9 (16-May-2019)
+
+#516: _inputPtr off-by-one in UTF8StreamJsonParser._parseNumber2()
+ (reported by Henrik G)
+#531: Non-blocking parser reports incorrect locations when fed with non-zero offset
+ (reported by David N)
+
 2.9.8 (15-Dec-2018)
 
 #488: Fail earlier on coercions from "too big" `BigInteger` into
   fixed-size types (`int`, `long`, `short`)
+#510: Fix ArrayIndexOutofBoundsException found by LGTM.com
+ (reported by Alexander E-T)
 - Improve exception message for missing Base64 padding (see databind#2183)
 
 2.9.7 (19-Sep-2018)


=====================================
src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java
=====================================
@@ -1960,7 +1960,7 @@ public class ReaderBasedJsonParser // final in 2.3, earlier
             }
             char c = _inputBuffer[_inputPtr];
             int i = (int) c;
-            if (i <= maxCode) {
+            if (i < maxCode) {
                 if (codes[i] != 0) {
                     break;
                 }


=====================================
src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java
=====================================
@@ -1467,7 +1467,7 @@ public class UTF8StreamJsonParser
         _textBuffer.setCurrentLength(outPtr);
         // As per #105, need separating space between root values; check here
         if (_parsingContext.inRoot()) {
-            _verifyRootSpace(_inputBuffer[_inputPtr++] & 0xFF);
+            _verifyRootSpace(_inputBuffer[_inputPtr] & 0xFF);
         }
 
         // And there we have it!


=====================================
src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParser.java
=====================================
@@ -94,6 +94,7 @@ public class NonBlockingJsonParser
         _currInputRowStart = start - (_inputEnd - _currInputRowStart);
 
         // And then update buffer settings
+        _currBufferStart = start;
         _inputBuffer = buf;
         _inputPtr = start;
         _inputEnd = end;


=====================================
src/test/java/com/fasterxml/jackson/core/json/TestRootValues.java
=====================================
@@ -79,7 +79,7 @@ public class TestRootValues
         _testSimpleWrites(true);
     }
 
-    public void _testSimpleWrites(boolean useStream) throws Exception
+    private void _testSimpleWrites(boolean useStream) throws Exception
     {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         StringWriter w = new StringWriter();
@@ -102,4 +102,102 @@ public class TestRootValues
         String json = useStream ? out.toString("UTF-8") : w.toString();
         assertEquals("123 \"abc\" true", json);
     }
+
+    // [core#516]: Off-by-one read problem
+    public void testRootOffsetIssue516Bytes() throws Exception
+    {
+        // InputStream that forces _parseNumber2 to be invoked.
+        final InputStream in = new Issue516InputStream(new byte[][] {
+            "1234".getBytes("UTF-8"),
+            "5 true".getBytes("UTF-8")
+        });
+
+        JsonParser parser = JSON_F.createParser(in);
+        assertEquals(12345, parser.nextIntValue(0));
+
+        // Fails with com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'rue': was expecting ('true', 'false' or 'null')
+        assertTrue(parser.nextBooleanValue());
+
+        parser.close();
+        in.close();
+    }
+
+    // [core#516]: Off-by-one read problem
+    public void testRootOffsetIssue516Chars() throws Exception
+    {
+        // InputStream that forces _parseNumber2 to be invoked.
+        final Reader in = new Issue516Reader(new char[][] {
+            "1234".toCharArray(), "5 true".toCharArray()
+        });
+
+        JsonParser parser = JSON_F.createParser(in);
+        assertEquals(12345, parser.nextIntValue(0));
+
+        // Fails with com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'rue': was expecting ('true', 'false' or 'null')
+        assertTrue(parser.nextBooleanValue());
+
+        parser.close();
+        in.close();
+    }
+
+    static class Issue516InputStream extends InputStream
+    {
+        private final byte[][] reads;
+        private int currentRead;
+
+        public Issue516InputStream(byte[][] reads) {
+            this.reads = reads;
+            this.currentRead = 0;
+        }
+
+        @Override
+        public int read() throws IOException {
+            throw new UnsupportedOperationException();
+        }
+    
+        @Override
+        public int read(byte[] b, int off, int len) throws IOException {
+            if (currentRead >= reads.length) {
+                return -1;
+            }
+            byte[] bytes = reads[currentRead++];
+            if (len < bytes.length) {
+                throw new IllegalArgumentException();
+            }
+            System.arraycopy(bytes, 0, b, off, bytes.length);
+            return bytes.length;
+        }
+    }
+
+    static class Issue516Reader extends Reader
+    {
+        private final char[][] reads;
+        private int currentRead;
+
+        public Issue516Reader(char[][] reads) {
+            this.reads = reads;
+            this.currentRead = 0;
+        }
+
+        @Override
+        public void close() { }
+
+        @Override
+        public int read() throws IOException {
+            throw new UnsupportedOperationException();
+        }
+    
+        @Override
+        public int read(char[] b, int off, int len) throws IOException {
+            if (currentRead >= reads.length) {
+                return -1;
+            }
+            char[] bytes = reads[currentRead++];
+            if (len < bytes.length) {
+                throw new IllegalArgumentException();
+            }
+            System.arraycopy(bytes, 0, b, off, bytes.length);
+            return bytes.length;
+        }
+    }
 }


=====================================
src/test/java/com/fasterxml/jackson/core/json/async/AsyncLocationTest.java
=====================================
@@ -0,0 +1,38 @@
+package com.fasterxml.jackson.core.json.async;
+
+import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.core.async.AsyncTestBase;
+import com.fasterxml.jackson.core.async.ByteArrayFeeder;
+
+public class AsyncLocationTest extends AsyncTestBase
+{
+    private final JsonFactory DEFAULT_F = new JsonFactory();
+
+    // for [core#531]
+    public void testLocationOffsets() throws Exception
+    {
+        JsonParser parser = DEFAULT_F.createNonBlockingByteArrayParser();
+        ByteArrayFeeder feeder = (ByteArrayFeeder) parser.getNonBlockingInputFeeder();
+
+        byte[] input = utf8Bytes("[[[");
+
+        feeder.feedInput(input, 2, 3);
+        assertEquals(JsonToken.START_ARRAY, parser.nextToken());
+        assertEquals(1, parser.getCurrentLocation().getByteOffset());
+        assertEquals(1, parser.getTokenLocation().getByteOffset());
+        assertEquals(1, parser.getCurrentLocation().getLineNr());
+        assertEquals(1, parser.getTokenLocation().getLineNr());
+        assertEquals(2, parser.getCurrentLocation().getColumnNr());
+        assertEquals(1, parser.getTokenLocation().getColumnNr());
+
+        feeder.feedInput(input, 0, 1);
+        assertEquals(JsonToken.START_ARRAY, parser.nextToken());
+        assertEquals(2, parser.getCurrentLocation().getByteOffset());
+        assertEquals(2, parser.getTokenLocation().getByteOffset());
+        assertEquals(1, parser.getCurrentLocation().getLineNr());
+        assertEquals(1, parser.getTokenLocation().getLineNr());
+        assertEquals(3, parser.getCurrentLocation().getColumnNr());
+        assertEquals(2, parser.getTokenLocation().getColumnNr());
+        parser.close();
+    }
+}


=====================================
src/test/java/com/fasterxml/jackson/core/main/TestGeneratorClosing.java
=====================================
@@ -1,7 +1,8 @@
 package com.fasterxml.jackson.core.main;
 
-
 import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.core.testsupport.ByteOutputStreamForTesting;
+import com.fasterxml.jackson.core.testsupport.StringWriterForTesting;
 
 import java.io.*;
 
@@ -19,64 +20,6 @@ import java.io.*;
  */
 public class TestGeneratorClosing extends BaseTest
 {
-    /*
-    /**********************************************************
-    /* Helper classes
-    /**********************************************************
-     */
-
-    final static class MyWriter extends StringWriter
-    {
-        boolean _isClosed = false;
-
-        public MyWriter() { }
-
-        @Override
-        public void close() throws IOException {
-            _isClosed = true;
-            super.close();
-        }
-        public boolean isClosed() { return _isClosed; }
-    }
-
-    final static class MyStream extends ByteArrayOutputStream
-    {
-        boolean _isClosed = false;
-
-        public MyStream() { }
-
-        @Override
-        public void close() throws IOException {
-            _isClosed = true;
-            super.close();
-        }
-        public boolean isClosed() { return _isClosed; }
-    }
-
-    static class MyBytes extends ByteArrayOutputStream
-    {
-        public int flushed = 0;
-
-        @Override
-        public void flush() throws IOException
-        {
-            ++flushed;
-            super.flush();
-        }
-    }
-
-    static class MyChars extends StringWriter
-    {
-        public int flushed = 0;
-
-        @Override
-        public void flush()
-        {
-            ++flushed;
-            super.flush();
-        }
-    }
-    
     /*
     /**********************************************************
     /* Unit tests
@@ -98,7 +41,7 @@ public class TestGeneratorClosing extends BaseTest
         f.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
         assertFalse(f.isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET));
         @SuppressWarnings("resource")
-        MyWriter output = new MyWriter();
+        ByteOutputStreamForTesting output = new ByteOutputStreamForTesting();
         JsonGenerator jg = f.createGenerator(output);
 
         // shouldn't be closed to begin with...
@@ -114,7 +57,7 @@ public class TestGeneratorClosing extends BaseTest
         JsonFactory f = new JsonFactory();
         f.enable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
         @SuppressWarnings("resource")
-        MyWriter output = new MyWriter();
+        ByteOutputStreamForTesting output = new ByteOutputStreamForTesting();
         JsonGenerator jg = f.createGenerator(output);
 
         // shouldn't be closed to begin with...
@@ -130,7 +73,7 @@ public class TestGeneratorClosing extends BaseTest
         JsonFactory f = new JsonFactory();
         f.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
         @SuppressWarnings("resource")
-        MyStream output = new MyStream();
+        ByteOutputStreamForTesting output = new ByteOutputStreamForTesting();
         JsonGenerator jg = f.createGenerator(output, JsonEncoding.UTF8);
 
         assertFalse(output.isClosed());
@@ -181,53 +124,52 @@ public class TestGeneratorClosing extends BaseTest
         assertEquals("{", sw.toString());
     }
 
-    // [JACKSON-401]
     @SuppressWarnings("resource")
     public void testAutoFlushOrNot() throws Exception
     {
         JsonFactory f = new JsonFactory();
         assertTrue(f.isEnabled(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM));
-        MyChars sw = new MyChars();
+        StringWriterForTesting sw = new StringWriterForTesting();
         JsonGenerator jg = f.createGenerator(sw);
         jg.writeStartArray();
         jg.writeEndArray();
-        assertEquals(0, sw.flushed);
+        assertEquals(0, sw.flushCount);
         jg.flush();
-        assertEquals(1, sw.flushed);
+        assertEquals(1, sw.flushCount);
         jg.close();
         
         // ditto with stream
-        MyBytes bytes = new MyBytes();
+        ByteOutputStreamForTesting bytes = new ByteOutputStreamForTesting();
         jg = f.createGenerator(bytes, JsonEncoding.UTF8);
         jg.writeStartArray();
         jg.writeEndArray();
-        assertEquals(0, bytes.flushed);
+        assertEquals(0, bytes.flushCount);
         jg.flush();
-        assertEquals(1, bytes.flushed);
+        assertEquals(1, bytes.flushCount);
         assertEquals(2, bytes.toByteArray().length);
         jg.close();
 
         // then disable and we should not see flushing again...
         f.disable(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM);
         // first with a Writer
-        sw = new MyChars();
+        sw = new StringWriterForTesting();
         jg = f.createGenerator(sw);
         jg.writeStartArray();
         jg.writeEndArray();
-        assertEquals(0, sw.flushed);
+        assertEquals(0, sw.flushCount);
         jg.flush();
-        assertEquals(0, sw.flushed);
+        assertEquals(0, sw.flushCount);
         jg.close();
         assertEquals("[]", sw.toString());
 
         // and then with OutputStream
-        bytes = new MyBytes();
+        bytes = new ByteOutputStreamForTesting();
         jg = f.createGenerator(bytes, JsonEncoding.UTF8);
         jg.writeStartArray();
         jg.writeEndArray();
-        assertEquals(0, bytes.flushed);
+        assertEquals(0, bytes.flushCount);
         jg.flush();
-        assertEquals(0, bytes.flushed);
+        assertEquals(0, bytes.flushCount);
         jg.close();
         assertEquals(2, bytes.toByteArray().length);
     }


=====================================
src/test/java/com/fasterxml/jackson/core/read/JsonParserTest.java
=====================================
@@ -461,7 +461,7 @@ public class JsonParserTest extends BaseTest
 
         p = JSON_FACTORY.createParser(new MockDataInput(input));
         assertEquals(JsonToken.START_ARRAY, p.nextToken());
-        // same BOM, but DataInput is more restrctive so can skip but offsets
+        // same BOM, but DataInput is more restrictive so can skip but offsets
         // are not reliable...
         loc = p.getTokenLocation();
         assertNotNull(loc);


=====================================
src/test/java/com/fasterxml/jackson/core/read/NonStandardParserFeaturesTest.java
=====================================
@@ -5,24 +5,6 @@ import com.fasterxml.jackson.core.*;
 public class NonStandardParserFeaturesTest
     extends com.fasterxml.jackson.core.BaseTest
 {
-    public void testSimpleUnquotedBytes() throws Exception {
-        _testSimpleUnquoted(MODE_INPUT_STREAM);
-        _testSimpleUnquoted(MODE_INPUT_STREAM_THROTTLED);
-        _testSimpleUnquoted(MODE_DATA_INPUT);
-    }
-
-    public void testSimpleUnquotedChars() throws Exception {
-        _testSimpleUnquoted(MODE_READER);
-    }
-    
-    public void testLargeUnquoted() throws Exception
-    {
-        _testLargeUnquoted(MODE_INPUT_STREAM);
-        _testLargeUnquoted(MODE_INPUT_STREAM_THROTTLED);
-        _testLargeUnquoted(MODE_DATA_INPUT);
-        _testLargeUnquoted(MODE_READER);
-    }
-
     public void testSingleQuotesDefault() throws Exception
     {
         _testSingleQuotesDefault(MODE_INPUT_STREAM);
@@ -98,88 +80,6 @@ public class NonStandardParserFeaturesTest
     /****************************************************************
      */
 
-    private void _testLargeUnquoted(int mode) throws Exception
-    {
-        StringBuilder sb = new StringBuilder(5000);
-        sb.append("[\n");
-        //final int REPS = 2000;
-        final int REPS = 1050;
-        for (int i = 0; i < REPS; ++i) {
-            if (i > 0) {
-                sb.append(',');
-                if ((i & 7) == 0) {
-                    sb.append('\n');
-                }
-            }
-            sb.append("{");
-            sb.append("abc").append(i&127).append(':');
-            sb.append((i & 1) != 0);
-            sb.append("}\n");
-        }
-        sb.append("]");
-        String JSON = sb.toString();
-        JsonFactory f = new JsonFactory();
-        f.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
-        JsonParser p = createParser(f, mode, JSON);
-        assertToken(JsonToken.START_ARRAY, p.nextToken());
-        for (int i = 0; i < REPS; ++i) {
-            assertToken(JsonToken.START_OBJECT, p.nextToken());
-            assertToken(JsonToken.FIELD_NAME, p.nextToken());
-            assertEquals("abc"+(i&127), p.getCurrentName());
-            assertToken(((i&1) != 0) ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE, p.nextToken());
-            assertToken(JsonToken.END_OBJECT, p.nextToken());
-        }
-        assertToken(JsonToken.END_ARRAY, p.nextToken());
-        p.close();
-    }
-
-    
-    private void _testSimpleUnquoted(int mode) throws Exception
-    {
-        final JsonFactory f = new JsonFactory();
-        f.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
-
-        String JSON = "{ a : 1, _foo:true, $:\"money!\", \" \":null }";
-        JsonParser p = createParser(f, mode, JSON);
-
-        assertToken(JsonToken.START_OBJECT, p.nextToken());
-        assertToken(JsonToken.FIELD_NAME, p.nextToken());
-        assertEquals("a", p.getCurrentName());
-        assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
-        assertToken(JsonToken.FIELD_NAME, p.nextToken());
-        assertEquals("_foo", p.getCurrentName());
-        assertToken(JsonToken.VALUE_TRUE, p.nextToken());
-        assertToken(JsonToken.FIELD_NAME, p.nextToken());
-        assertEquals("$", p.getCurrentName());
-        assertToken(JsonToken.VALUE_STRING, p.nextToken());
-        assertEquals("money!", p.getText());
-
-        // and then regular quoted one should still work too:
-        assertToken(JsonToken.FIELD_NAME, p.nextToken());
-        assertEquals(" ", p.getCurrentName());
-
-        assertToken(JsonToken.VALUE_NULL, p.nextToken());
-
-        assertToken(JsonToken.END_OBJECT, p.nextToken());
-        p.close();
-
-        // Another thing, as per [Issue#102]: numbers
-
-        JSON = "{ 123:true,4:false }";
-        p = createParser(f, mode, JSON);
-
-        assertToken(JsonToken.START_OBJECT, p.nextToken());
-        assertToken(JsonToken.FIELD_NAME, p.nextToken());
-        assertEquals("123", p.getCurrentName());
-        assertToken(JsonToken.VALUE_TRUE, p.nextToken());
-
-        assertToken(JsonToken.FIELD_NAME, p.nextToken());
-        assertEquals("4", p.getCurrentName());
-        assertToken(JsonToken.VALUE_FALSE, p.nextToken());
-
-        assertToken(JsonToken.END_OBJECT, p.nextToken());
-        p.close();
-    }
 
     /**
      * Test to verify that the default parser settings do not


=====================================
src/test/java/com/fasterxml/jackson/core/read/NonStandardUnquotedNamesTest.java
=====================================
@@ -0,0 +1,139 @@
+package com.fasterxml.jackson.core.read;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+public class NonStandardUnquotedNamesTest
+    extends com.fasterxml.jackson.core.BaseTest
+{
+    private final JsonFactory UNQUOTED_FIELDS_F = new JsonFactory();
+    {
+        UNQUOTED_FIELDS_F.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
+    }
+
+    public void testSimpleUnquotedBytes() throws Exception {
+        _testSimpleUnquoted(MODE_INPUT_STREAM);
+        _testSimpleUnquoted(MODE_INPUT_STREAM_THROTTLED);
+        _testSimpleUnquoted(MODE_DATA_INPUT);
+    }
+
+    public void testSimpleUnquotedChars() throws Exception {
+        _testSimpleUnquoted(MODE_READER);
+    }
+
+    public void testLargeUnquoted() throws Exception
+    {
+        _testLargeUnquoted(MODE_INPUT_STREAM);
+        _testLargeUnquoted(MODE_INPUT_STREAM_THROTTLED);
+        _testLargeUnquoted(MODE_DATA_INPUT);
+        _testLargeUnquoted(MODE_READER);
+    }
+
+    // [core#510]: ArrayIndexOutOfBounds
+    public void testUnquotedIssue510() throws Exception
+    {
+        // NOTE! Requires longer input buffer to trigger longer codepath
+        char[] fullChars = new char[4001];
+        for (int i = 0; i < 3998; i++) {
+             fullChars[i] = ' ';
+        }
+        fullChars[3998] = '{';
+        fullChars[3999] = 'a';
+        fullChars[4000] = 256;
+
+        JsonParser p = UNQUOTED_FIELDS_F.createParser(new java.io.StringReader(new String(fullChars)));
+        assertToken(JsonToken.START_OBJECT, p.nextToken());
+        try {
+            p.nextToken();
+            fail("Should not pass");
+        } catch (JsonParseException e) {
+            ; // should fail here
+        }
+        p.close();
+    }
+
+    /*
+    /****************************************************************
+    /* Secondary test methods
+    /****************************************************************
+     */
+    
+    private void _testLargeUnquoted(int mode) throws Exception
+    {
+        StringBuilder sb = new StringBuilder(5000);
+        sb.append("[\n");
+        //final int REPS = 2000;
+        final int REPS = 1050;
+        for (int i = 0; i < REPS; ++i) {
+            if (i > 0) {
+                sb.append(',');
+                if ((i & 7) == 0) {
+                    sb.append('\n');
+                }
+            }
+            sb.append("{");
+            sb.append("abc").append(i&127).append(':');
+            sb.append((i & 1) != 0);
+            sb.append("}\n");
+        }
+        sb.append("]");
+        String JSON = sb.toString();
+        JsonParser p = createParser(UNQUOTED_FIELDS_F, mode, JSON);
+        assertToken(JsonToken.START_ARRAY, p.nextToken());
+        for (int i = 0; i < REPS; ++i) {
+            assertToken(JsonToken.START_OBJECT, p.nextToken());
+            assertToken(JsonToken.FIELD_NAME, p.nextToken());
+            assertEquals("abc"+(i&127), p.getCurrentName());
+            assertToken(((i&1) != 0) ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE, p.nextToken());
+            assertToken(JsonToken.END_OBJECT, p.nextToken());
+        }
+        assertToken(JsonToken.END_ARRAY, p.nextToken());
+        p.close();
+    }
+
+    private void _testSimpleUnquoted(int mode) throws Exception
+    {
+        String JSON = "{ a : 1, _foo:true, $:\"money!\", \" \":null }";
+        JsonParser p = createParser(UNQUOTED_FIELDS_F, mode, JSON);
+
+        assertToken(JsonToken.START_OBJECT, p.nextToken());
+        assertToken(JsonToken.FIELD_NAME, p.nextToken());
+        assertEquals("a", p.getCurrentName());
+        assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
+        assertToken(JsonToken.FIELD_NAME, p.nextToken());
+        assertEquals("_foo", p.getCurrentName());
+        assertToken(JsonToken.VALUE_TRUE, p.nextToken());
+        assertToken(JsonToken.FIELD_NAME, p.nextToken());
+        assertEquals("$", p.getCurrentName());
+        assertToken(JsonToken.VALUE_STRING, p.nextToken());
+        assertEquals("money!", p.getText());
+
+        // and then regular quoted one should still work too:
+        assertToken(JsonToken.FIELD_NAME, p.nextToken());
+        assertEquals(" ", p.getCurrentName());
+
+        assertToken(JsonToken.VALUE_NULL, p.nextToken());
+
+        assertToken(JsonToken.END_OBJECT, p.nextToken());
+        p.close();
+
+        // Another thing, as per [Issue#102]: numbers
+
+        JSON = "{ 123:true,4:false }";
+        p = createParser(UNQUOTED_FIELDS_F, mode, JSON);
+
+        assertToken(JsonToken.START_OBJECT, p.nextToken());
+        assertToken(JsonToken.FIELD_NAME, p.nextToken());
+        assertEquals("123", p.getCurrentName());
+        assertToken(JsonToken.VALUE_TRUE, p.nextToken());
+
+        assertToken(JsonToken.FIELD_NAME, p.nextToken());
+        assertEquals("4", p.getCurrentName());
+        assertToken(JsonToken.VALUE_FALSE, p.nextToken());
+
+        assertToken(JsonToken.END_OBJECT, p.nextToken());
+        p.close();
+    }
+}


=====================================
src/test/java/com/fasterxml/jackson/core/testsupport/ByteOutputStreamForTesting.java
=====================================
@@ -0,0 +1,32 @@
+package com.fasterxml.jackson.core.testsupport;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * Helper class for verifying that {@link java.io.OutputStream} is (or is not)
+ * closed and/or flushed.
+ */
+public class ByteOutputStreamForTesting extends ByteArrayOutputStream
+{
+    public int closeCount = 0;
+    public int flushCount = 0;
+
+    public ByteOutputStreamForTesting() { }
+
+    @Override
+    public void close() throws IOException {
+        ++closeCount;
+        super.close();
+    }
+
+    @Override
+    public void flush() throws IOException
+    {
+        ++flushCount;
+        super.flush();
+    }
+
+    public boolean isClosed() { return closeCount > 0; }
+    public boolean isFlushed() { return flushCount > 0; }
+}


=====================================
src/test/java/com/fasterxml/jackson/core/testsupport/StringWriterForTesting.java
=====================================
@@ -0,0 +1,28 @@
+package com.fasterxml.jackson.core.testsupport;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+public class StringWriterForTesting extends StringWriter
+{
+    public int closeCount = 0;
+    public int flushCount = 0;
+
+    public StringWriterForTesting() { }
+
+    @Override
+    public void close() throws IOException {
+        ++closeCount;
+        super.close();
+    }
+
+    @Override
+    public void flush()
+    {
+        ++flushCount;
+        super.flush();
+    }
+
+    public boolean isClosed() { return closeCount > 0; }
+    public boolean isFlushed() { return flushCount > 0; }
+}


=====================================
src/test/java/com/fasterxml/jackson/failing/LocationOffsets533Test.java
=====================================
@@ -0,0 +1,124 @@
+package com.fasterxml.jackson.failing;
+
+import com.fasterxml.jackson.core.*;
+
+// For checking [databind#533]
+public class LocationOffsets533Test extends com.fasterxml.jackson.core.BaseTest
+{
+    final JsonFactory JSON_F = new JsonFactory();
+
+    public void testOffsetWithoutInputOffset() throws Exception
+    {
+        JsonLocation loc;
+        JsonParser p;
+        // 3 spaces before, 2 after, just for padding
+        byte[] b = "   { }  ".getBytes("UTF-8");
+
+        // and then peel them off
+        p = JSON_F.createParser(/*ObjectReadContext.empty(),*/ b);
+        assertToken(JsonToken.START_OBJECT, p.nextToken());
+
+        loc = p.getTokenLocation();
+        assertEquals(3L, loc.getByteOffset());
+        assertEquals(-1L, loc.getCharOffset());
+        assertEquals(1, loc.getLineNr());
+        assertEquals(4, loc.getColumnNr());
+
+        loc = p.getCurrentLocation();
+        assertEquals(4L, loc.getByteOffset());
+        assertEquals(-1L, loc.getCharOffset());
+        assertEquals(1, loc.getLineNr());
+        assertEquals(5, loc.getColumnNr());
+
+        p.close();
+    }
+
+    // for [core#533]
+    public void testUtf8Bom() throws Exception
+    {
+        JsonLocation loc;
+        JsonParser p;
+
+        byte[] b = withUtf8Bom("{ }".getBytes());
+
+        // and then peel them off
+        p = JSON_F.createParser(/*ObjectReadContext.empty(),*/ b);
+        assertToken(JsonToken.START_OBJECT, p.nextToken());
+
+        loc = p.getTokenLocation();
+        assertEquals(3L, loc.getByteOffset());
+        assertEquals(-1L, loc.getCharOffset());
+        assertEquals(1, loc.getLineNr());
+        assertEquals(4, loc.getColumnNr());
+
+        loc = p.getCurrentLocation();
+        assertEquals(4L, loc.getByteOffset());
+        assertEquals(-1L, loc.getCharOffset());
+        assertEquals(1, loc.getLineNr());
+        assertEquals(5, loc.getColumnNr());
+
+        p.close();
+    }
+
+    public void testUtf8BomWithPadding() throws Exception
+    {
+        JsonLocation loc;
+        JsonParser p;
+
+        byte[] b = withUtf8Bom("   { }".getBytes());
+
+        // and then peel them off
+        p = JSON_F.createParser(/*ObjectReadContext.empty(),*/ b);
+        assertToken(JsonToken.START_OBJECT, p.nextToken());
+
+        loc = p.getTokenLocation();
+        assertEquals(6L, loc.getByteOffset());
+        assertEquals(-1L, loc.getCharOffset());
+        assertEquals(1, loc.getLineNr());
+        assertEquals(7, loc.getColumnNr());
+
+        loc = p.getCurrentLocation();
+        assertEquals(7L, loc.getByteOffset());
+        assertEquals(-1L, loc.getCharOffset());
+        assertEquals(1, loc.getLineNr());
+        assertEquals(8, loc.getColumnNr());
+
+        p.close();
+    }
+
+    public void testUtf8BomWithInputOffset() throws Exception
+    {
+        JsonLocation loc;
+        JsonParser p;
+
+        byte[] b = withUtf8Bom("   { }".getBytes());
+
+        // and then peel them off
+        p = JSON_F.createParser(/*ObjectReadContext.empty(),*/ b);
+        assertToken(JsonToken.START_OBJECT, p.nextToken());
+
+        loc = p.getTokenLocation();
+        assertEquals(6L, loc.getByteOffset());
+        assertEquals(-1L, loc.getCharOffset());
+        assertEquals(1, loc.getLineNr());
+        assertEquals(7, loc.getColumnNr());
+
+        loc = p.getCurrentLocation();
+        assertEquals(7L, loc.getByteOffset());
+        assertEquals(-1L, loc.getCharOffset());
+        assertEquals(1, loc.getLineNr());
+        assertEquals(8, loc.getColumnNr());
+
+        p.close();
+    }
+
+    private byte[] withUtf8Bom(byte[] bytes) {
+        byte[] arr = new byte[bytes.length + 3];
+        // write UTF-8 BOM
+        arr[0] = (byte) 0xEF;
+        arr[1] = (byte) 0xBB;
+        arr[2] = (byte) 0xBF;
+        System.arraycopy(bytes, 0, arr, 3, bytes.length);
+        return arr;
+    }
+}



View it on GitLab: https://salsa.debian.org/java-team/jackson-core/commit/5f14fbd7db7abe4d351e9bb3d9df2e6a376c53c4

-- 
View it on GitLab: https://salsa.debian.org/java-team/jackson-core/commit/5f14fbd7db7abe4d351e9bb3d9df2e6a376c53c4
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20190915/5a58f754/attachment.html>


More information about the pkg-java-commits mailing list