# Rest Client - Precondition RunTimeException - JDK 17

**URL:** <https://forum.opensearch.org/t/rest-client-precondition-runtimeexception-jdk-17/14778>\
**Category:** OpenSearch Client Libraries\
**Tags:** opensearch-java\
**Created:** [June 21, 2023, 3:29pm UTC](https://forum.opensearch.org/t/rest-client-precondition-runtimeexception-jdk-17/14778 "2023-06-21T15:29:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![docme](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@docme](https://forum.opensearch.org/u/docme)\
**Post date:** [June 21, 2023, 3:29pm UTC](https://forum.opensearch.org/t/rest-client-precondition-runtimeexception-jdk-17/14778/1 "2023-06-21T15:29:50Z")

</div>

(relevant - OpenSearch):

Describe: In porting to JDK 17 (error does not occur up thru JDK16), I am receiving a runtime outOfBoundsCheckFromIndexSize(oobef, fromIndex, size, length) exception from jdk.internal.util,Preconditions class. This only occurs once (initially) when creating a new index. The example OpenSearch code from the highlevelrest client below triggers the error on the low level client.

Configuration: OpenSearch 2.6, SprintBootStarterWeb 3.0.6 (occurs on 2.x versions as well) - JDK17 and above

Example Code:

lowLevelRestClient = restClient.getLowLevelClient();

NodesSniffer nodesniffer = new OpenSearchNodesSniffer(  
lowLevelRestClient,  
TimeUnit.SECONDS.toMillis(5),  
OpenSearchNodesSniffer.Scheme.HTTPS);

Sniffer sniffer = Sniffer.builder(lowLevelRestClient)  
.setNodesSniffer(nodesniffer)  
.build();

SniffOnFailureListener listener = new SniffOnFailureListener();  
listener.setSniffer(sniffer);

CreateIndexRequest createIndexRequest = new CreateIndexRequest(“test-my”);  
createIndexRequest.settings(Settings.builder()  
.put(“index.number\_of\_shards”, 1)  
.put(“index.number\_of\_replicas”, 0)  
);

```
		try {
			HashMap<String, String> typeMapping = new HashMap<String, String>();
			typeMapping.put("type", "integer");
			HashMap<String, Object> ageMapping = new HashMap<String, Object>();
			ageMapping.put("age", typeMapping);
			HashMap<String, Object> mapping = new HashMap<String, Object>();
			mapping.put("properties", ageMapping);
			createIndexRequest.mapping(mapping);
			CreateIndexResponse createIndexResponse = restClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
			System.out.println("\nCreating index:");
			System.out.println("Is client acknowledged?" + ((createIndexResponse.isAcknowledged()) ? " Yes" : " No"));
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

```

We can work around this problem, so its not a high priority for us. Planning to convert to Java Client at 3.0 release.

Thanks

---

<div class="post-metadata">

**Author:** ![wbeckler](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@wbeckler](https://forum.opensearch.org/u/wbeckler)\
**Post date:** [June 22, 2023, 8:00pm UTC](https://forum.opensearch.org/t/rest-client-precondition-runtimeexception-jdk-17/14778/2 "2023-06-22T20:00:35Z")

</div>

I’m curious, what is the motivation for converting to Java Client at 3.0 release but not sooner?

---

<div class="post-metadata">

**Author:** ![docme](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@docme](https://forum.opensearch.org/u/docme)\
**Post date:** [June 23, 2023, 11:57am UTC](https://forum.opensearch.org/t/rest-client-precondition-runtimeexception-jdk-17/14778/3 "2023-06-23T11:57:00Z")

</div>

We have not verified all of our High Level Rest (HLR) api usage and related aggregation code can be ported directly. HLR works for and there is no need to take on an uncertain project until required, which will be on or about the 3.0 release

---

<div class="post-metadata">

**Author:** ![docme](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@docme](https://forum.opensearch.org/u/docme)\
**Post date:** [August 10, 2023, 1:26pm UTC](https://forum.opensearch.org/t/rest-client-precondition-runtimeexception-jdk-17/14778/4 "2023-08-10T13:26:38Z")

</div>

# Generic Rest Client

Will the current High Level Rest Client be deprecated in 3.0 before a generic REST client (Issue #417) is available? Our code utilizes JSON exclusively (versus Java Classes), allowing us to specify the specific fields to return in a search query.

---

<div class="post-metadata">

**Author:** ![reta](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@reta](https://forum.opensearch.org/u/reta)\
**Post date:** [August 10, 2023, 2:21pm UTC](https://forum.opensearch.org/t/rest-client-precondition-runtimeexception-jdk-17/14778/5 "2023-08-10T14:21:48Z")

</div>

@docme The plan (for now as per [1]) is to deprecate REST clients in 3.0.0 and remove them in 4.0.0, thank you

[1] [[META] Deprecate REST client · Issue #5424 · opensearch-project/OpenSearch · GitHub](https://github.com/opensearch-project/OpenSearch/issues/5424)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)\
**Post date:** [October 9, 2023, 2:22pm UTC](https://forum.opensearch.org/t/rest-client-precondition-runtimeexception-jdk-17/14778/6 "2023-10-09T14:22:05Z")

</div>

Closed on October 9, 2023, 2:22pm UTC

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