Browse Source

Upgrade to Jackson 2.8.10 (#27230)

While it's not possible to upgrade the Jackson dependencies 
to their latest versions yet (see #27032 (comment) for more) 
it's still possible to upgrade to the latest 2.8.x version.
Tanguy Leroux 8 years ago
parent
commit
43e7a4a349

+ 2 - 2
buildSrc/version.properties

@@ -5,8 +5,8 @@ lucene            = 7.1.0
 # optional dependencies
 spatial4j         = 0.6
 jts               = 1.13
-jackson           = 2.8.6
-snakeyaml         = 1.15
+jackson           = 2.8.10
+snakeyaml         = 1.17
 # when updating log4j, please update also docs/java-api/index.asciidoc
 log4j             = 2.9.1
 slf4j             = 1.6.2

+ 1 - 0
client/sniffer/licenses/jackson-core-2.8.10.jar.sha1

@@ -0,0 +1 @@
+eb21a035c66ad307e66ec8fce37f5d50fd62d039

+ 0 - 1
client/sniffer/licenses/jackson-core-2.8.6.jar.sha1

@@ -1 +0,0 @@
-2ef7b1cc34de149600f5e75bc2d5bf40de894e60

+ 1 - 0
core/licenses/jackson-core-2.8.10.jar.sha1

@@ -0,0 +1 @@
+eb21a035c66ad307e66ec8fce37f5d50fd62d039

+ 0 - 1
core/licenses/jackson-core-2.8.6.jar.sha1

@@ -1 +0,0 @@
-2ef7b1cc34de149600f5e75bc2d5bf40de894e60

+ 1 - 0
core/licenses/jackson-dataformat-cbor-2.8.10.jar.sha1

@@ -0,0 +1 @@
+1c58cc9313ddf19f0900cd61ed044874278ce320

+ 0 - 1
core/licenses/jackson-dataformat-cbor-2.8.6.jar.sha1

@@ -1 +0,0 @@
-b88721371cfa2d7242bb5e52fe70861aa061c050

+ 1 - 0
core/licenses/jackson-dataformat-smile-2.8.10.jar.sha1

@@ -0,0 +1 @@
+e853081fadaad3e98ed801937acc3d8f77580686

+ 0 - 1
core/licenses/jackson-dataformat-smile-2.8.6.jar.sha1

@@ -1 +0,0 @@
-71590ad45cee21249774e2f93e5eca66e446cef3

+ 1 - 0
core/licenses/jackson-dataformat-yaml-2.8.10.jar.sha1

@@ -0,0 +1 @@
+1e08caf1d787c825307d8cc6362452086020d853

+ 0 - 1
core/licenses/jackson-dataformat-yaml-2.8.6.jar.sha1

@@ -1 +0,0 @@
-8bd44d50f9a6cdff9c7578ea39d524eb519e35ab

+ 0 - 1
core/licenses/snakeyaml-1.15.jar.sha1

@@ -1 +0,0 @@
-3b132bea69e8ee099f416044970997bde80f4ea6

+ 1 - 0
core/licenses/snakeyaml-1.17.jar.sha1

@@ -0,0 +1 @@
+7a27ea250c5130b2922b86dea63cbb1cc10a660c

+ 4 - 2
core/src/main/java/org/elasticsearch/common/io/FastStringReader.java

@@ -34,6 +34,7 @@ public class FastStringReader extends Reader implements CharSequence {
     private int length;
     private int next = 0;
     private int mark = 0;
+    private boolean closed = false;
 
     /**
      * Creates a new string reader.
@@ -49,8 +50,9 @@ public class FastStringReader extends Reader implements CharSequence {
      * Check to make sure that the stream has not been closed
      */
     private void ensureOpen() throws IOException {
-        if (length == -1)
+        if (closed) {
             throw new IOException("Stream closed");
+        }
     }
 
     @Override
@@ -196,7 +198,7 @@ public class FastStringReader extends Reader implements CharSequence {
      */
     @Override
     public void close() {
-        length = -1;
+        closed = true;
     }
 
     @Override

+ 42 - 0
core/src/test/java/org/elasticsearch/common/xcontent/XContentParserTests.java

@@ -42,6 +42,48 @@ import static org.hamcrest.Matchers.nullValue;
 
 public class XContentParserTests extends ESTestCase {
 
+    public void testFloat() throws IOException {
+        final XContentType xContentType = randomFrom(XContentType.values());
+
+        final String field = randomAlphaOfLengthBetween(1, 5);
+        final Float value = randomFloat();
+
+        try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) {
+            builder.startObject();
+            if (randomBoolean()) {
+                builder.field(field, value);
+            } else {
+                builder.field(field).value(value);
+            }
+            builder.endObject();
+
+            final Number number;
+            try (XContentParser parser = createParser(xContentType.xContent(), builder.bytes())) {
+                assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
+                assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
+                assertEquals(field, parser.currentName());
+                assertEquals(XContentParser.Token.VALUE_NUMBER, parser.nextToken());
+
+                number = parser.numberValue();
+
+                assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
+                assertNull(parser.nextToken());
+            }
+
+            assertEquals(value, number.floatValue(), 0.0f);
+
+            if (xContentType == XContentType.CBOR) {
+                // CBOR parses back a float
+                assertTrue(number instanceof Float);
+            } else {
+                // JSON, YAML and SMILE parses back the float value as a double
+                // This will change for SMILE in Jackson 2.9 where all binary based
+                // formats will return a float
+                assertTrue(number instanceof Double);
+            }
+        }
+    }
+
     public void testReadList() throws IOException {
         assertThat(readList("{\"foo\": [\"bar\"]}"), contains("bar"));
         assertThat(readList("{\"foo\": [\"bar\",\"baz\"]}"), contains("bar", "baz"));

+ 1 - 1
test/framework/src/main/java/org/elasticsearch/test/RandomObjects.java

@@ -108,7 +108,7 @@ public final class RandomObjects {
                         //with CBOR we get back a float
                         expectedParsedValues.add(randomFloat);
                     } else if (xContentType == XContentType.SMILE) {
-                        //with SMILE we get back a double
+                        //with SMILE we get back a double (this will change in Jackson 2.9 where it will return a Float)
                         expectedParsedValues.add(randomFloat.doubleValue());
                     } else {
                         //with JSON AND YAML we get back a double, but with float precision.