Skip to content

XContentParser with excludes filters emits invalid json in common cases #80142

Open
@weizijun

Description

@weizijun

Elasticsearch version (bin/elasticsearch --version): master

Plugins installed: [] no

JVM version (java -version):

OS version (uname -a if on a Unix-like system):

Description of the problem including expected versus actual behavior:

Steps to reproduce:

Please include a minimal but complete recreation of the problem,
including (e.g.) index creation, mappings, settings, query etc. The easier
you make for us to reproduce it, the more likely that somebody will take the
time to look at it.

  1. add a test in AbstractXContentFilteringTestCase
    public void testExcludesFailed() throws IOException {
        final Builder sample = builder -> builder.startObject().field("bar", "test1").field("foo", "test2").endObject();
        Builder expected = builder -> builder.startObject().field("bar", "test1").field("foo", "test2").endObject();
        testFilter(expected, sample, emptySet(), singleton("bar.xxx"));
    }
  1. throw the exception:
com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value

	at __randomizedtesting.SeedInfo.seed([D5C7EEE02AA53137:388E1895E77A618D]:0)
	at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:2080)
	at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:220)
	at com.fasterxml.jackson.core.JsonGenerator._copyCurrentContents(JsonGenerator.java:1938)
	at com.fasterxml.jackson.core.JsonGenerator.copyCurrentStructure(JsonGenerator.java:1914)
	at org.elasticsearch.xcontent.json.JsonXContentGenerator.copyCurrentStructure(JsonXContentGenerator.java:396)
	at org.elasticsearch.xcontent.XContentBuilder.copyCurrentStructure(XContentBuilder.java:1161)
	at org.elasticsearch.xcontent.support.filtering.AbstractXContentFilteringTestCase.filterOnParser(AbstractXContentFilteringTestCase.java:87)
	at org.elasticsearch.xcontent.support.filtering.AbstractXContentFilteringTestCase.testExcludesFailed(AbstractXContentFilteringTestCase.java:94)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1758)
	at com.carrotsearch.randomizedtesting.RandomizedRunner$8.evaluate(RandomizedRunner.java:946)
	at com.carrotsearch.randomizedtesting.RandomizedRunner$9.evaluate(RandomizedRunner.java:982)

I think the right action is passed the test.
It appears in excludes mode.
when excludes pattern contain than longer than input. like:

{
  "bar" : "test1",
  "foo" : "test2"
}

and the pattern is : bar.xxx.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions