# Painless:Cannot invoke \\”Object.getClass()\\” because \\”callArgs\[0\]\\” is null

**URL:** <https://discuss.elastic.co/t/painless-cannot-invoke-object-getclass-because-callargs-0-is-null/261506>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [January 19, 2021, 8:08am UTC](https://discuss.elastic.co/t/painless-cannot-invoke-object-getclass-because-callargs-0-is-null/261506 "2021-01-19T08:08:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carpeDiem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carpediem/32/88362_2.png) [@carpeDiem](https://discuss.elastic.co/u/carpeDiem)\
**Post date:** [January 19, 2021, 8:08am UTC](https://discuss.elastic.co/t/painless-cannot-invoke-object-getclass-because-callargs-0-is-null/261506/1 "2021-01-19T08:08:17Z")

</div>

Hello experts,  
I am using a painless scripting language to query,but the hit of result is empty.  
This is my query body.

```auto
POST test_script-0/_search
{
        "_source":true,
        "aggs":{},
        "from":0,
        "highlight":{
            "fields":{
                "*":{
                    "fragment_size":10000
                }
            },
            "post_tags":[
                "@/kibana-highlighted-field@"
            ],
            "pre_tags":[
                "@kibana-highlighted-field@"
            ],
            "require_field_match":false
        },
        "query":{
            "bool":{
                "filter":[],
                "must":[
                    {
                        "range":{
                            "@timestamp":{
                                "format":"epoch_millis||yyyy-MM-dd HH:mm:ss",
                                "gte":1609403799250,
                                "lt":1610699799250
                            }
                        }
                    },
                    {
                        "script":{
                            "script":{
                                "inline":"\n try{\n Matcher m = /(?<ar1fbe9185f4feeb15eb9577e31c5f5394>\\d+)/.matcher(String.valueOf(params['_source']['freeSize']));\n m.find();\n String f = m.group(1);\n f==\"487883268096\"\n }catch(Exception e){}",
                                "lang":"painless"
                            }
                        }
                    }
                ],
                "must_not":[],
                "should":[]
            }
        },
        "size":10,
        "sort":[
            {
                "@timestamp":{
                    "missing":"_last",
                    "order":"desc",
                    "unmapped_type":"date"
                }
            }
        ]
    }

```

Then I take a testing, I create an index with a document first.

```auto
POST test_script-0/_doc
{
    "@timestamp":"2021-01-16T02:58:19.000Z",
    "freeSize":"487883268096"
}

```

I delete the operation of catching the exception,this is my query body,then I got an error.

```auto
{
  "_source": true,
  "aggs": {},
  "from": 0,
  "highlight": {
    "fields": {
      "*": {
        "fragment_size": 10000
      }
    },
    "post_tags": [
      "@/kibana-highlighted-field@"
    ],
    "pre_tags": [
      "@kibana-highlighted-field@"
    ],
    "require_field_match": false
  },
  "query": {
    "bool": {
      "filter": [],
      "must": [
        {
          "script": {
            "script": {
              "inline": "Matcher m = /(?<ar1fbe9185f4feeb15eb9577e31c5f5394>\\d+)/.matcher(String.valueOf(params['_source']['freeSize'])); m.find(); String f = m.group(1); f==\"487883268096\";",
              "lang": "painless"
            }
          }
        }
      ],
      "must_not": [],
      "should": [
       
      ]
    }
  },
  "size": 10,
  "sort": [
    {
      "@timestamp": {
        "missing": "_last",
        "order": "desc",
        "unmapped_type": "date"
      }
    }
  ]
}

```

When executing, I have the following error.

 ![企业微信截图_16107652692598](https://us1.discourse-cdn.com/elastic/original/3X/7/7/772427372dcabac172eccbab396fdf3c58842737.png)  
Are there some ideas for it ? How do I do to solve it?

Looking forward to any help! Thank you!

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stu/32/75063_2.png) [@stu](https://discuss.elastic.co/u/stu)\
**Post date:** [February 1, 2021, 11:44pm UTC](https://discuss.elastic.co/t/painless-cannot-invoke-object-getclass-because-callargs-0-is-null/261506/2 "2021-02-01T23:44:55Z")

</div>

That error occurs when trying to perform an operation on a `def` type that is `null`. In this case, `params['_source']` is `null`.

`freeSize` is in `doc`, not in params in the painless [filter context](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-filter-context.html).

Assuming `freeSize` is a String, you can use `doc['freeSize.keyword'].value` to get to it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 1, 2021, 11:45pm UTC](https://discuss.elastic.co/t/painless-cannot-invoke-object-getclass-because-callargs-0-is-null/261506/3 "2021-03-01T23:45:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
