Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in IntervalQueryBuilder.toString() #50036

Closed
prasad2kin opened this issue Dec 10, 2019 · 2 comments
Closed

NullPointerException in IntervalQueryBuilder.toString() #50036

prasad2kin opened this issue Dec 10, 2019 · 2 comments
Labels
:Search/Search Search-related issues that do not fall into other categories

Comments

@prasad2kin
Copy link

Elasticsearch version (bin/elasticsearch --version): Version: 7.3.2, Build: oss/tar/1c1faf1/2019-09-06T14:40:30.409026Z, JVM: 1.8.0_162

Plugins installed: All defaults i.e [aggs-matrix-stats, analysis-common, ingest-common, ingest-geoip, ingest-user-agent, lang-expression, lang-mustache, lang-painless, mapper-extras, parent-join, percolator, rank-eval, reindex, repository-url, transport-netty4, advanced-scripts-plugin, analysis-kuromoji, analysis-smartcn]

JVM version (java -version): 1.8.0_162

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

Description of the problem including expected versus actual behavior:

A NullPointerException is thrown when toString() method is called on an instance of IntervalQueryBuilder.

Steps to reproduce:
Create the following query using the Java code as follows:

{
	"intervals": {
		"test": {
			"all_of": {
				"intervals": [
					{
						"match": {
							"query": "audio"
						}
					},
					{
						"match": {
							"query": "method"
						}
					}
				],
				"filter": {
					"script": {
						"source": "interval.gaps > distance",
						"params": {
							"distance": 2
						}
					}
				}
			}
		}
	}
}

Use the java code as follows:

    private IntervalsSourceProvider createSource(int distance){
        try {
            XContentBuilder xb = jsonBuilder()
                            .startObject()
                                .startObject("all_of")
                                    .startArray("intervals")
                                        .startObject()
                                            .startObject("match")
                                                .field("query", "audio")
                                            .endObject()
                                        .endObject()
                                        .startObject()
                                        .startObject("match")
                                        .field("query", "method")
                                        .endObject()
                                        .endObject()
                                    .endArray()
                                    .startObject("filter")
                                        .startObject("script")
                                            .field("source", "interval.gaps > distance")
                                            .startObject("params")
                                                .field("distance", distance)
                                            .endObject()
                                        .endObject()
                                    .endObject()
                                .endObject()
                            .endObject();
            try(XContentParser parser = XContentFactory.xContent(XContentType.JSON)
                    .createParser(NamedXContentRegistry.EMPTY,
                            DeprecationHandler.THROW_UNSUPPORTED_OPERATION, BytesReference.bytes(xb).streamInput())) {

                parser.nextToken(); // advance past the first starting object
                parser.nextToken();
                IntervalsSourceProvider is = IntervalsSourceProvider.fromXContent(parser);
                System.out.println((new IntervalQueryBuilder("test", is)).toString());
                return is;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

You will see NPE during System.out.println((new IntervalQueryBuilder("test", is)).toString());

Provide logs (if relevant):

exception java.lang.NullPointerException
	at org.elasticsearch.index.query.IntervalsSourceProvider$IntervalFilter.toXContent(IntervalsSourceProvider.java:777)
	at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:857)
	at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:850)
	at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:842)
	at org.elasticsearch.index.query.IntervalsSourceProvider$Combine.toXContent(IntervalsSourceProvider.java:422)
	at org.elasticsearch.index.query.IntervalQueryBuilder.doXContent(IntervalQueryBuilder.java:69)
	at org.elasticsearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:83)
	at org.elasticsearch.common.Strings.toString(Strings.java:778)
	at org.elasticsearch.index.query.AbstractQueryBuilder.toString(AbstractQueryBuilder.java:363)

@cbuescher cbuescher added the :Search/Search Search-related issues that do not fall into other categories label Dec 10, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

@cbuescher
Copy link
Member

Thanks for raising this and the reproduction. I think this particular NPE was fixed by #49793 in 7.6 and on master, so this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

No branches or pull requests

3 participants