Skip to content

Commit

Permalink
Update to Jackson 2.8.1
Browse files Browse the repository at this point in the history
This commit updates Jackson to the 2.8.1 version, which is more strict when it comes to build objects. It also adds the snakeyaml dependency that was previously shaded in jackson libs.

It also closes elastic#18076
  • Loading branch information
tlrx committed Aug 5, 2016
1 parent a01475a commit 841d5a2
Show file tree
Hide file tree
Showing 28 changed files with 374 additions and 66 deletions.
2 changes: 0 additions & 2 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]SimulatePipelineRequestParsingTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]SimulatePipelineResponseTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]WriteableIngestDocumentTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]search[/\\]MultiSearchRequestTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]search[/\\]SearchRequestBuilderTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]AutoCreateIndexTests.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]IndicesOptionsTests.java" checks="LineLength" />
Expand Down Expand Up @@ -1009,7 +1008,6 @@
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]aggregations[/\\]bucket[/\\]ShardReduceIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]aggregations[/\\]bucket[/\\]ShardSizeTestCase.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]aggregations[/\\]bucket[/\\]SignificantTermsIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]aggregations[/\\]bucket[/\\]SignificantTermsSignificanceScoreIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]aggregations[/\\]bucket[/\\]TermsDocCountErrorIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]aggregations[/\\]bucket[/\\]TermsShardMinDocCountIT.java" checks="LineLength" />
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]aggregations[/\\]bucket[/\\]nested[/\\]NestedAggregatorTests.java" checks="LineLength" />
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ lucene = 6.1.0
# optional dependencies
spatial4j = 0.6
jts = 1.13
jackson = 2.7.1
jackson = 2.8.1
snakeyaml = 1.15
log4j = 1.2.17
slf4j = 1.6.2
jna = 4.2.2
Expand Down
1 change: 0 additions & 1 deletion client/sniffer/licenses/jackson-core-2.7.1.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/sniffer/licenses/jackson-core-2.8.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fd13b1c033741d48291315c6370f7d475a42dccf
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dependencies {
compile 'org.joda:joda-convert:1.2'

// json and yaml
compile "org.yaml:snakeyaml:${versions.snakeyaml}"
compile "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${versions.jackson}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${versions.jackson}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.core.base.GeneratorBase;
import com.fasterxml.jackson.core.filter.FilteringGeneratorDelegate;
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.core.json.JsonWriteContext;
import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import org.elasticsearch.common.bytes.BytesReference;
Expand Down Expand Up @@ -271,7 +272,9 @@ private void writeStartRaw(String fieldName) throws IOException {
public void writeEndRaw() {
assert base != null : "JsonGenerator should be of instance GeneratorBase but was: " + generator.getClass();
if (base != null) {
base.getOutputContext().writeValue();
JsonStreamContext context = base.getOutputContext();
assert (context instanceof JsonWriteContext) : "Expected an instance of JsonWriteContext but was: " + context.getClass();
((JsonWriteContext) context).writeValue();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ public String text() throws IOException {

@Override
public BytesRef utf8Bytes() throws IOException {
// Tentative workaround for https://github.com/elastic/elasticsearch/issues/8629
// TODO: Remove this when we upgrade jackson to 2.6.x.
if (parser.getTextLength() == 0) {
return new BytesRef();
}
return new BytesRef(CharBuffer.wrap(parser.getTextCharacters(), parser.getTextOffset(), parser.getTextLength()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,33 @@
public class MultiSearchRequestTests extends ESTestCase {
public void testSimpleAdd() throws Exception {
MultiSearchRequest request = parseMultiSearchRequest("/org/elasticsearch/action/search/simple-msearch1.json");
assertThat(request.requests().size(), equalTo(8));
assertThat(request.requests().get(0).indices()[0], equalTo("test"));
assertThat(request.requests().get(0).indicesOptions(), equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().get(0).types().length, equalTo(0));
assertThat(request.requests().get(1).indices()[0], equalTo("test"));
assertThat(request.requests().get(1).indicesOptions(), equalTo(IndicesOptions.fromOptions(false, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().get(1).types()[0], equalTo("type1"));
assertThat(request.requests().get(2).indices()[0], equalTo("test"));
assertThat(request.requests().get(2).indicesOptions(), equalTo(IndicesOptions.fromOptions(false, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().get(3).indices()[0], equalTo("test"));
assertThat(request.requests().get(3).indicesOptions(), equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().get(4).indices()[0], equalTo("test"));
assertThat(request.requests().get(4).indicesOptions(), equalTo(IndicesOptions.fromOptions(true, false, false, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().size(),
equalTo(8));
assertThat(request.requests().get(0).indices()[0],
equalTo("test"));
assertThat(request.requests().get(0).indicesOptions(),
equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().get(0).types().length,
equalTo(0));
assertThat(request.requests().get(1).indices()[0],
equalTo("test"));
assertThat(request.requests().get(1).indicesOptions(),
equalTo(IndicesOptions.fromOptions(false, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().get(1).types()[0],
equalTo("type1"));
assertThat(request.requests().get(2).indices()[0],
equalTo("test"));
assertThat(request.requests().get(2).indicesOptions(),
equalTo(IndicesOptions.fromOptions(false, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().get(3).indices()[0],
equalTo("test"));
assertThat(request.requests().get(3).indicesOptions(),
equalTo(IndicesOptions.fromOptions(true, true, true, true, IndicesOptions.strictExpandOpenAndForbidClosed())));
assertThat(request.requests().get(4).indices()[0],
equalTo("test"));
assertThat(request.requests().get(4).indicesOptions(),
equalTo(IndicesOptions.fromOptions(true, false, false, true, IndicesOptions.strictExpandOpenAndForbidClosed())));

assertThat(request.requests().get(5).indices(), is(Strings.EMPTY_ARRAY));
assertThat(request.requests().get(5).types().length, equalTo(0));
assertThat(request.requests().get(6).indices(), is(Strings.EMPTY_ARRAY));
Expand Down Expand Up @@ -119,10 +133,27 @@ public void testSimpleAdd4() throws Exception {
}

public void testResponseErrorToXContent() throws IOException {
MultiSearchResponse response = new MultiSearchResponse(new MultiSearchResponse.Item[]{new MultiSearchResponse.Item(null, new IllegalStateException("foobar")), new MultiSearchResponse.Item(null, new IllegalStateException("baaaaaazzzz"))});
MultiSearchResponse response = new MultiSearchResponse(
new MultiSearchResponse.Item[]{
new MultiSearchResponse.Item(null, new IllegalStateException("foobar")),
new MultiSearchResponse.Item(null, new IllegalStateException("baaaaaazzzz"))
});

XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertEquals("\"responses\"[{\"error\":{\"root_cause\":[{\"type\":\"illegal_state_exception\",\"reason\":\"foobar\"}],\"type\":\"illegal_state_exception\",\"reason\":\"foobar\"},\"status\":500},{\"error\":{\"root_cause\":[{\"type\":\"illegal_state_exception\",\"reason\":\"baaaaaazzzz\"}],\"type\":\"illegal_state_exception\",\"reason\":\"baaaaaazzzz\"},\"status\":500}]",
builder.endObject();

assertEquals("{\"responses\":["
+ "{"
+ "\"error\":{\"root_cause\":[{\"type\":\"illegal_state_exception\",\"reason\":\"foobar\"}],"
+ "\"type\":\"illegal_state_exception\",\"reason\":\"foobar\"},\"status\":500"
+ "},"
+ "{"
+ "\"error\":{\"root_cause\":[{\"type\":\"illegal_state_exception\",\"reason\":\"baaaaaazzzz\"}],"
+ "\"type\":\"illegal_state_exception\",\"reason\":\"baaaaaazzzz\"},\"status\":500"
+ "}"
+ "]}",
builder.string());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public void testWriteMapValueWithNullKeys() throws IOException {
public void testWriteFieldMapWithNullKeys() throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
try {
builder.startObject();
builder.field("map", Collections.singletonMap(null, "test"));
fail("write map should have failed");
} catch(IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,12 @@ public void testSearchAnalyzerSerialization() throws IOException {
.endObject()
.endObject().endObject().endObject().string();
mapper = parser.parse("type", new CompressedXContent(mapping));
XContentBuilder builder = XContentFactory.jsonBuilder();

XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
mapper.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true")));
builder.endObject();

String mappingString = builder.string();
assertTrue(mappingString.contains("analyzer"));
assertTrue(mappingString.contains("search_analyzer"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,12 @@ public void testSearchAnalyzerSerialization() throws IOException {
.endObject()
.endObject().endObject().endObject().string();
mapper = parser.parse("type", new CompressedXContent(mapping));
XContentBuilder builder = XContentFactory.jsonBuilder();

XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
mapper.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true")));
builder.endObject();

String mappingString = builder.string();
assertTrue(mappingString.contains("analyzer"));
assertTrue(mappingString.contains("search_analyzer"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.translog.Translog.Location;
Expand Down Expand Up @@ -351,10 +354,14 @@ public void testStats() throws IOException {

assertEquals(6, copy.estimatedNumberOfOperations());
assertEquals(431, copy.getTranslogSizeInBytes());
assertEquals("\"translog\"{\n" +
" \"operations\" : 6,\n" +
" \"size_in_bytes\" : 431\n" +
"}", copy.toString().trim());

try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
builder.startObject();
copy.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();

assertEquals("{\"translog\":{\"operations\":6,\"size_in_bytes\":431}}", builder.string());
}

try {
new TranslogStats(1, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,14 @@ private void comparePluginsAndModules(NodeInfo nodeInfo, NodeInfo readNodeInfo)
private void compareJsonOutput(ToXContent param1, ToXContent param2) throws IOException {
ToXContent.Params params = ToXContent.EMPTY_PARAMS;
XContentBuilder param1Builder = jsonBuilder();
XContentBuilder param2Builder = jsonBuilder();
param1Builder.startObject();
param1.toXContent(param1Builder, params);
param1Builder.endObject();

XContentBuilder param2Builder = jsonBuilder();
param2Builder.startObject();
param2.toXContent(param2Builder, params);
param2Builder.endObject();
assertThat(param1Builder.string(), equalTo(param2Builder.string()));
}

Expand Down
Loading

0 comments on commit 841d5a2

Please sign in to comment.