# TransportAddress instantiation error

**URL:** <https://discuss.elastic.co/t/transportaddress-instantiation-error/187665>\
**Category:** Elasticsearch\
**Created:** [June 26, 2019, 7:35pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665 "2019-06-26T19:35:35Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jem](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jem](https://discuss.elastic.co/u/jem)\
**Post date:** [June 26, 2019, 7:35pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/1 "2019-06-26T19:35:35Z")

</div>

I am getting the following error:  
java.lang.InstantiationError: org.elasticsearch.common.transport.TransportAddress

I am using 7.2.0 which is many versions ahead from what I had been using but in earlier versions same error. I think in some versions the class was abstract and not instantiable.

I am attempting to instantiate the class as follows:

new TransportAddress(host, port);

Is there a fundamental reason why this would not work or would the error come from, e.g., a bad host or port?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 26, 2019, 8:07pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/2 "2019-06-26T20:07:28Z")

</div>

May be. But anyway you should use the Rest Client as the TransportClient will be removed in the next major version.

---

<div class="post-metadata">

**Author:** ![jem](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jem](https://discuss.elastic.co/u/jem)\
**Post date:** [June 27, 2019, 5:32pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/3 "2019-06-27T17:32:34Z")

</div>

RestClient instead of TransportAddress or instead of TransportClient? I am getting an error instantiating TransportAddress.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 27, 2019, 9:56pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/4 "2019-06-27T21:56:18Z")

</div>

RestClient instead of TransportClient.

What are you using this class for?

---

<div class="post-metadata">

**Author:** ![jem](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jem](https://discuss.elastic.co/u/jem)\
**Post date:** [June 27, 2019, 10:33pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/5 "2019-06-27T22:33:39Z")

</div>

I did not explicitly mention TransportClient; my problem was with TransportAddress which I am trying to instantiate using a constructor I think I saw in the documentation. Is TransportClient relevant to this?

I think I might not be able to instantiate TransportAddress (which I am doing from cached data) but instead need to use InetSocketTransportAddress since apparently (at least in some versions of the library) TransportAddress is abstract.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 28, 2019, 5:56am UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/6 "2019-06-28T05:56:04Z")

</div>

What are you using this class for?  
Any code to share?

---

<div class="post-metadata">

**Author:** ![jem](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jem](https://discuss.elastic.co/u/jem)\
**Post date:** [June 28, 2019, 5:08pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/7 "2019-06-28T17:08:57Z")

</div>

The constructor use as shown in the first post:  
TransportAddress t = new TransportAddress(host, port);

is the what I am trying to do. I do not get a compile but rather a runtime error. If TransportAddress is abstract, maybe I should just use a concrete subclass, specifically InetSocketTransportAddress? I am not sure what led us to try TransportAddress.

Using this because we are storing strings representing host and port and want to recreate the TransportAddress from cache.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 28, 2019, 5:20pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/8 "2019-06-28T17:20:20Z")

</div>

My question is "what do you need a TransportAddress for?"  
What are you trying to do with that?

---

<div class="post-metadata">

**Author:** ![jem](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jem](https://discuss.elastic.co/u/jem)\
**Post date:** [June 28, 2019, 5:46pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/9 "2019-06-28T17:46:18Z")

</div>

TransportAddress is the type of a List which is a field in TransportClient which are updating.  
So have you been saying all along we should be using RestClient instead which maybe does not have this List? And if there is no List in RestClient, how do we do the equivalent of adding/removing elements from this list?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 28, 2019, 6:01pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/10 "2019-06-28T18:01:33Z")

</div>

Ok. So I finally got my answer. You want to build a client. Great.

Here's the documentation [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html)

Feel free to ask questions if you are not able to make it work.

---

<div class="post-metadata">

**Author:** ![jem](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jem](https://discuss.elastic.co/u/jem)\
**Post date:** [June 28, 2019, 7:23pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/11 "2019-06-28T19:23:10Z")

</div>

Strictly speaking i want to modify an existing client object. We are invoking on the TransportClient object the methods addTransportAddress() and removeTransportAddress(). These two methods take TransportAddress objects that I am trying to recreate from cached values.

It is not clear to me at this point how to do this with the Rest Client -- it does not appear to have a list of such addresses.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 28, 2019, 7:57pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/12 "2019-06-28T19:57:36Z")

</div>

May be the sniffer is what you want. Hard to say as I have no idea of what you really want to do at the end. Which problem do you think you would solve?

---

<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 26, 2019, 7:57pm UTC](https://discuss.elastic.co/t/transportaddress-instantiation-error/187665/13 "2019-07-26T19:57:57Z")

</div>

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