# Delete Watch by Java API get NPE

**URL:** <https://discuss.elastic.co/t/delete-watch-by-java-api-get-npe/33136>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 28, 2015, 9:23am UTC](https://discuss.elastic.co/t/delete-watch-by-java-api-get-npe/33136 "2015-10-28T09:23:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enniu\_51](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enniu_51/32/5310_2.png) [@Enniu\_51](https://discuss.elastic.co/u/Enniu_51)\
**Post date:** [October 28, 2015, 9:23am UTC](https://discuss.elastic.co/t/delete-watch-by-java-api-get-npe/33136/1 "2015-10-28T09:23:29Z")

</div>

In `org.elasticsearch.client.transport.support`:

```
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void execute(final Action<Request, Response, RequestBuilder> action, final Request request, ActionListener<Response> listener) {
    final TransportActionNodeProxy<Request, Response> proxy = proxies.get(action);
    //try to get action "cluster:admin/watcher/watch/delete" but returns null
    nodesService.execute(new TransportClientNodesService.NodeListenerCallback<Response>() {
        @Override
        public void doWithNode(DiscoveryNode node, ActionListener<Response> listener) {
            proxy.execute(node, request, listener);//proxy is null, so get NPE
        }
    }, listener);
}

```

The code to create client:

```
        client = TransportClient.builder().settings(
                Settings.settingsBuilder().put("cluster.name", "elasticsearch_dc_001").build()
        ).build()
                .addTransportAddress(
                        new InetSocketTransportAddress(
                                InetAddress.getByName("x.x.x.x"), 9300
                        )
                );

```

The code to delete watch:

```
    DeleteWatchResponse deleteWatchResponse = watcherClient.prepareDeleteWatch(getName(config)).setForce(true).get();

```

Full stack trace:

```
Exception in thread "main" java.lang.NullPointerException
	at org.elasticsearch.client.transport.support.TransportProxyClient$1.doWithNode(TransportProxyClient.java:58)
	at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:202)
	at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
	at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:272)
	at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:347)
	at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85)
	at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59)
	at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:67)
	at com.enniu.cloud.services.elasticsearch.WatcherManager.deleteWatch(WatcherManager.java:115)
	at com.enniu.cloud.services.elasticsearch.WatcherManager.lambda$delete$2(WatcherManager.java:100)
	at com.enniu.cloud.services.elasticsearch.WatcherManager$$Lambda$2/2128859746.apply(Unknown Source)
	at com.enniu.cloud.services.elasticsearch.WatcherManager.performOnWatch(WatcherManager.java:109)
	at com.enniu.cloud.services.elasticsearch.WatcherManager.delete(WatcherManager.java:99)
	at com.enniu.cloud.services.elasticsearch.WatcherManager.main(WatcherManager.java:133)

```

JAVA API version:

```
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>watcher</artifactId>
        <version>2.0.0-rc1</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>license</artifactId>
        <version>2.0.0-rc1</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.0.0-rc1</version>
    </dependency>
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 28, 2015, 9:27am UTC](https://discuss.elastic.co/t/delete-watch-by-java-api-get-npe/33136/2 "2015-10-28T09:27:04Z")

</div>

please see the other topic [here](https://discuss.elastic.co/t/maven-couldnt-transfer-elasticsearch-watcher-pom-2-0-0-rc1-due-to-authorization/33030/5?u=spinscale)

---

<div class="post-metadata">

**Author:** ![Umit\_Seren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/umit_seren/32/44933_2.png) [@Umit\_Seren](https://discuss.elastic.co/u/Umit_Seren)\
**Post date:** [December 28, 2015, 3:11pm UTC](https://discuss.elastic.co/t/delete-watch-by-java-api-get-npe/33136/3 "2015-12-28T15:11:09Z")

</div>

Same issue.  
I also added the plugin.types ([http://stackoverflow.com/questions/33430240/elasticsearch-2-0-how-to-delete-by-query-in-java](http://stackoverflow.com/questions/33430240/elasticsearch-2-0-how-to-delete-by-query-in-java)) but I get the same NullPointerException when trying to execute a delete-by-query through TransportClient.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 28, 2015, 5:22pm UTC](https://discuss.elastic.co/t/delete-watch-by-java-api-get-npe/33136/4 "2015-12-28T17:22:24Z")

</div>

Hey,

can you open a new issue, with code snippets showing the watcher action you execute via the WatcherClient as well as the telling us the version you are using so we can debug your issue further?

--Alex

---

<div class="post-metadata">

**Author:** ![Umit\_Seren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/umit_seren/32/44933_2.png) [@Umit\_Seren](https://discuss.elastic.co/u/Umit_Seren)\
**Post date:** [December 29, 2015, 8:42am UTC](https://discuss.elastic.co/t/delete-watch-by-java-api-get-npe/33136/5 "2015-12-29T08:42:15Z")

</div>

Thanks for the feedback. I think I posted in the wrong thread. I get the NPE actually when I use the delete-by-query plugin. But it seems to be happen in the same place. I will create an issue tough.

---

<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:** [July 6, 2017, 1:47pm UTC](https://discuss.elastic.co/t/delete-watch-by-java-api-get-npe/33136/6 "2017-07-06T13:47:36Z")

</div>


