# Watcher error - null pointer exception

**URL:** https://discuss.elastic.co/t/watcher-error-null-pointer-exception/262975
**Category:** Elasticsearch
**Tags:** painless
**Created:** [February 2, 2021, 12:57pm UTC](https://discuss.elastic.co/t/watcher-error-null-pointer-exception/262975 "2021-02-02T12:57:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![firstpostcommenter](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@firstpostcommenter](https://discuss.elastic.co/u/firstpostcommenter)
#### Post date: [February 2, 2021, 12:57pm UTC](https://discuss.elastic.co/t/watcher-error-null-pointer-exception/262975/1 "2021-02-02T12:57:59Z")

</div>

Hi,  
I seem to have similar problem mentioned in [Problem execute watcher "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null"](https://discuss.elastic.co/t/problem-execute-watcher-cannot-invoke-object-getclass-because-callargs-0-is-null/255763)

Sample JSON:

```auto
        "aggs": {
                "unique_customerid": {
                  "terms": {
                    "field": "CustomerID.keyword"
                  }
                }
              }
            }
          }
        }
      },
      "condition": {
        "script": {
          "source": "return ctx.payload.aggregations.unique_customerid.buckets.stream().count() > 1",
          "lang": "painless"
        }
      },

```

In Kibana logs I see that CustomerID.keyword exists so I am not sure why I get nullpointer exception here in this condition.

```auto
  "exception": {
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "return ctx.payload.aggregations.unique_customerid.buckets.stream().count() > 1",
      " ^---- HERE"
    ],
    "script": "return ctx.payload.aggregations.unique_customerid.buckets.stream().count() > 1",
    "lang": "painless",
    "position": {
      "offset": 31,
      "start": 0,
      "end": 78
    },
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null",
      "stack_trace": "java.lang.NullPointerException: Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null\n\tat 

```

---

<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 18, 2021, 3:12pm UTC](https://discuss.elastic.co/t/watcher-error-null-pointer-exception/262975/2 "2021-02-18T15:12:34Z")

</div>

Hi, that looks like there's a null in your aggregation payload. You can inspect the contents of `ctx.payload.aggregations` with `Debug.explain(ctx.payload.aggregations)`.

In context:  
`Debug.explain(ctx.payload.aggregations); return ctx.payload.aggregations.unique_customerid.buckets.stream().count() > 1`.

This will throw an exception with the contents of `ctx.payload.aggregations`, which will help us narrow down the issue.

---

<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 18, 2021, 3:13pm UTC](https://discuss.elastic.co/t/watcher-error-null-pointer-exception/262975/3 "2021-03-18T15:13:12Z")

</div>

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