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

Simple for-loop throws null_pointer_exception in painless #28501

Closed
MrOrz opened this issue Feb 2, 2018 · 2 comments
Closed

Simple for-loop throws null_pointer_exception in painless #28501

MrOrz opened this issue Feb 2, 2018 · 2 comments
Assignees

Comments

@MrOrz
Copy link

MrOrz commented Feb 2, 2018

Elasticsearch version (bin/elasticsearch --version):
6.1.0 (build hash: c0c1ba0)

Plugins installed:
Using official docker image docker.elastic.co/elasticsearch/elasticsearch:6.1.0

JVM version (java -version):
Using official docker image docker.elastic.co/elasticsearch/elasticsearch:6.1.0

OS version (uname -a if on a Unix-like system):
Docker host machine: OSX 10.11.6

Description of the problem including expected versus actual behavior:

When a painless script contains a for-loop that contains an variable assignment in its first clause, it would cause a compile error and null_pointer_exception.

I.e. This causes null_pointer_exception:

int i; for(i=0; i<3; i+=1) {}

But this works:

for(int i=0; i<3; i+=1) {}

This also works:

int i=0; for(; i<3; i+=1) {}

Steps to reproduce:

  1. Start a blank elasticsearch DB and index an arbitrary document (just to provide a doc to manipulate. Mappings are irrelevant.)
curl -PUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
 "foo": "bar"
}
'
  1. Invoke a update query with for-loop
curl -POST 'localhost:9200/my_index/my_type/1/_update?pretty' -H 'Content-Type: application/json' -d'
{
  "script": {
    "source": "int i; for(i=0; i<3; i+=1) {}\n ctx.op = \"none\"",
    "lang": "painless"
  }
}
'

Expected

Successful response with no-op like:

{
  "_index" : "my_index",
  "_type" : "my_type",
  "_id" : "1",
  "_version" : 1,
  "result" : "noop",
  "_shards" : {
    "total" : 0,
    "successful" : 0,
    "failed" : 0
  }
}

Actual
Status-400 response with "compile error" and "null_pointer_exception":

{
  "error" : {
    "root_cause" : [
      {
        "type" : "remote_transport_exception",
        "reason" : "[hbJSTB8][172.17.0.2:9300][indices:data/write/update[s]]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "failed to execute script",
    "caused_by" : {
      "type" : "script_exception",
      "reason" : "compile error",
      "script_stack" : [ ],
      "script" : "int i; for(i=0; i<3; i+=1) {}\n ctx.op = \"none\"",
      "lang" : "painless",
      "caused_by" : {
        "type" : "null_pointer_exception",
        "reason" : null
      }
    }
  },
  "status" : 400
}

Possibly relates to #24695

@jdconrad
Copy link
Contributor

jdconrad commented Feb 2, 2018

@MrOrz Thank you for the bug report. I was able to repro. Will look into this soon.

@jdconrad
Copy link
Contributor

jdconrad commented Feb 5, 2018

This has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants