# IndexOutOfBoundsException at IndexShardRoutingTable class

**URL:** <https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599>\
**Category:** Elasticsearch\
**Created:** [March 26, 2014, 4:53am UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599 "2014-03-26T04:53:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shinsuke\_Sugaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinsuke_sugaya/32/1208_2.png) [@Shinsuke\_Sugaya](https://discuss.elastic.co/u/Shinsuke_Sugaya)\
**Post date:** [March 26, 2014, 4:53am UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599/1 "2014-03-26T04:53:15Z")

</div>

Hi

I encountered the following problem:

Caused by: java.lang.IndexOutOfBoundsException: index (-2) must not be  
negative  
at  
org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:306)  
at  
org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:285)  
at  
org.elasticsearch.common.collect.RegularImmutableList.get(RegularImmutableList.java:65)  
at  
org.elasticsearch.cluster.routing.IndexShardRoutingTable.preferNodeActiveInitializingShardsIt(IndexShardRoutingTable.java:378)  
at  
org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.preferenceActiveShardIterator(PlainOperationRouting.java:210)  
at  
org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.getShards(PlainOperationRouting.java:80)  
at  
org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:80)  
at  
org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:42)  
at  
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:121)  
at  
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:97)  
at  
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:74)  
at  
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:49)  
at  
org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:63)  
at  
org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:49)  
at  
org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:85)  
at  
org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:174)  
... 9 more

My environment is:

- Elasticserach 0.90.7
- 3 nodes in a cluster
- Send GET request with preference=\_local

Looking into IndexShardRoutingTable class, it seems that "loc" is  
an unexpected negative value at the following code. pickIndex method  
returns a value of "counter"(incremental value). If "counter" achieves  
Integer.MAX\_VALUE, I think that "loc" is negative and then  
activeShards.get(loc) throws the exception.

```
    int index = pickIndex();
    for (int i = 0; i < activeShards.size(); i++) {
        int loc = (index + i) % activeShards.size();

```

If it's a bug, I'll file an issue.

Best regards,  
shinsuke

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/bd03dfc5-6cc6-4788-aec3-cea98e4abe2d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bd03dfc5-6cc6-4788-aec3-cea98e4abe2d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Kevin\_Wang](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@Kevin\_Wang](https://discuss.elastic.co/u/Kevin_Wang)\
**Post date:** [March 26, 2014, 10:43am UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599/2 "2014-03-26T10:43:20Z")

</div>

pickIndex() will return the absolute value of the count, so it won't return  
a negative value. Can you provide more details?

Kevin

On Wednesday, March 26, 2014 3:53:15 PM UTC+11, Shinsuke Sugaya wrote:

> Hi
> 
> I encountered the following problem:
> 
> Caused by: java.lang.IndexOutOfBoundsException: index (-2) must not be  
> negative  
> at  
> org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:306)  
> at  
> org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:285)  
> at  
> org.elasticsearch.common.collect.RegularImmutableList.get(RegularImmutableList.java:65)  
> at  
> org.elasticsearch.cluster.routing.IndexShardRoutingTable.preferNodeActiveInitializingShardsIt(IndexShardRoutingTable.java:378)  
> at  
> org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.preferenceActiveShardIterator(PlainOperationRouting.java:210)  
> at  
> org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.getShards(PlainOperationRouting.java:80)  
> at  
> org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:80)  
> at  
> org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:42)  
> at  
> org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:121)  
> at  
> org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:97)  
> at  
> org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:74)  
> at  
> org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:49)  
> at  
> org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:63)  
> at  
> org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:49)  
> at  
> org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:85)  
> at  
> org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:174)  
> ... 9 more
> 
> My environment is:
> 
> - Elasticserach 0.90.7
> - 3 nodes in a cluster
> - Send GET request with preference=\_local
> 
> Looking into IndexShardRoutingTable class, it seems that "loc" is  
> an unexpected negative value at the following code. pickIndex method  
> returns a value of "counter"(incremental value). If "counter" achieves  
> Integer.MAX\_VALUE, I think that "loc" is negative and then  
> activeShards.get(loc) throws the exception.
> 
> ```
> int index = pickIndex();
> for (int i = 0; i < activeShards.size(); i++) {
> int loc = (index + i) % activeShards.size();
> 
> ```
> 
> If it's a bug, I'll file an issue.
> 
> Best regards,  
> shinsuke

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/908dc93c-e7b6-4a03-802e-fe6e18f30f10%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/908dc93c-e7b6-4a03-802e-fe6e18f30f10%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Shinsuke\_Sugaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinsuke_sugaya/32/1208_2.png) [@Shinsuke\_Sugaya](https://discuss.elastic.co/u/Shinsuke_Sugaya)\
**Post date:** [March 26, 2014, 12:58pm UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599/3 "2014-03-26T12:58:16Z")

</div>

> ```
> int loc = (index + i) % activeShards.size();
> 
> ```

index is NOT negative, but (index + i) is negative.

Regards,  
shinsuke

2014年3月26日水曜日 19時43分20秒 UTC+9 Kevin Wang:

> pickIndex() will return the absolute value of the count, so it won't  
> return a negative value. Can you provide more details?
> 
> Kevin
> 
> On Wednesday, March 26, 2014 3:53:15 PM UTC+11, Shinsuke Sugaya wrote:
> 
> > Hi
> > 
> > I encountered the following problem:
> > 
> > Caused by: java.lang.IndexOutOfBoundsException: index (-2) must not be  
> > negative  
> > at  
> > org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:306)  
> > at  
> > org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:285)  
> > at  
> > org.elasticsearch.common.collect.RegularImmutableList.get(RegularImmutableList.java:65)  
> > at  
> > org.elasticsearch.cluster.routing.IndexShardRoutingTable.preferNodeActiveInitializingShardsIt(IndexShardRoutingTable.java:378)  
> > at  
> > org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.preferenceActiveShardIterator(PlainOperationRouting.java:210)  
> > at  
> > org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.getShards(PlainOperationRouting.java:80)  
> > at  
> > org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:80)  
> > at  
> > org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:42)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:121)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:97)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:74)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:49)  
> > at  
> > org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:63)  
> > at  
> > org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:49)  
> > at  
> > org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:85)  
> > at  
> > org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:174)  
> > ... 9 more
> > 
> > My environment is:
> > 
> > - Elasticserach 0.90.7
> > - 3 nodes in a cluster
> > - Send GET request with preference=\_local
> > 
> > Looking into IndexShardRoutingTable class, it seems that "loc" is  
> > an unexpected negative value at the following code. pickIndex method  
> > returns a value of "counter"(incremental value). If "counter" achieves  
> > Integer.MAX\_VALUE, I think that "loc" is negative and then  
> > activeShards.get(loc) throws the exception.
> > 
> > ```
> > int index = pickIndex();
> > for (int i = 0; i < activeShards.size(); i++) {
> > int loc = (index + i) % activeShards.size();
> > 
> > ```
> > 
> > If it's a bug, I'll file an issue.
> > 
> > Best regards,  
> > shinsuke

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f3649939-fa7b-4db6-b3d5-b1eb3329abed%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f3649939-fa7b-4db6-b3d5-b1eb3329abed%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [March 26, 2014, 3:42pm UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599/4 "2014-03-26T15:42:06Z")

</div>

that is actually a bug IMO - Math.abs() can return -1 if it hits  
Integer.MIN\_VALUE

this code is just broken - can you open an issue!

On Wednesday, March 26, 2014 11:43:20 AM UTC+1, Kevin Wang wrote:

> pickIndex() will return the absolute value of the count, so it won't  
> return a negative value. Can you provide more details?
> 
> Kevin
> 
> On Wednesday, March 26, 2014 3:53:15 PM UTC+11, Shinsuke Sugaya wrote:
> 
> > Hi
> > 
> > I encountered the following problem:
> > 
> > Caused by: java.lang.IndexOutOfBoundsException: index (-2) must not be  
> > negative  
> > at  
> > org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:306)  
> > at  
> > org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:285)  
> > at  
> > org.elasticsearch.common.collect.RegularImmutableList.get(RegularImmutableList.java:65)  
> > at  
> > org.elasticsearch.cluster.routing.IndexShardRoutingTable.preferNodeActiveInitializingShardsIt(IndexShardRoutingTable.java:378)  
> > at  
> > org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.preferenceActiveShardIterator(PlainOperationRouting.java:210)  
> > at  
> > org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.getShards(PlainOperationRouting.java:80)  
> > at  
> > org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:80)  
> > at  
> > org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:42)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:121)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:97)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:74)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:49)  
> > at  
> > org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:63)  
> > at  
> > org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:49)  
> > at  
> > org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:85)  
> > at  
> > org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:174)  
> > ... 9 more
> > 
> > My environment is:
> > 
> > - Elasticserach 0.90.7
> > - 3 nodes in a cluster
> > - Send GET request with preference=\_local
> > 
> > Looking into IndexShardRoutingTable class, it seems that "loc" is  
> > an unexpected negative value at the following code. pickIndex method  
> > returns a value of "counter"(incremental value). If "counter" achieves  
> > Integer.MAX\_VALUE, I think that "loc" is negative and then  
> > activeShards.get(loc) throws the exception.
> > 
> > ```
> > int index = pickIndex();
> > for (int i = 0; i < activeShards.size(); i++) {
> > int loc = (index + i) % activeShards.size();
> > 
> > ```
> > 
> > If it's a bug, I'll file an issue.
> > 
> > Best regards,  
> > shinsuke

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/00ea862f-6104-411c-a786-47fd5c79d462%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/00ea862f-6104-411c-a786-47fd5c79d462%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [March 26, 2014, 3:55pm UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599/5 "2014-03-26T15:55:56Z")

</div>

I opened an issue for  
this: [IndexShardRoutingTable might barf if it has handled lots of searches... · Issue #5559 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/5559)

On Wednesday, March 26, 2014 5:53:15 AM UTC+1, Shinsuke Sugaya wrote:

> Hi
> 
> I encountered the following problem:
> 
> Caused by: java.lang.IndexOutOfBoundsException: index (-2) must not be  
> negative  
> at  
> org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:306)  
> at  
> org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:285)  
> at  
> org.elasticsearch.common.collect.RegularImmutableList.get(RegularImmutableList.java:65)  
> at  
> org.elasticsearch.cluster.routing.IndexShardRoutingTable.preferNodeActiveInitializingShardsIt(IndexShardRoutingTable.java:378)  
> at  
> org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.preferenceActiveShardIterator(PlainOperationRouting.java:210)  
> at  
> org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.getShards(PlainOperationRouting.java:80)  
> at  
> org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:80)  
> at  
> org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:42)  
> at  
> org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:121)  
> at  
> org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:97)  
> at  
> org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:74)  
> at  
> org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:49)  
> at  
> org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:63)  
> at  
> org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:49)  
> at  
> org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:85)  
> at  
> org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:174)  
> ... 9 more
> 
> My environment is:
> 
> - Elasticserach 0.90.7
> - 3 nodes in a cluster
> - Send GET request with preference=\_local
> 
> Looking into IndexShardRoutingTable class, it seems that "loc" is  
> an unexpected negative value at the following code. pickIndex method  
> returns a value of "counter"(incremental value). If "counter" achieves  
> Integer.MAX\_VALUE, I think that "loc" is negative and then  
> activeShards.get(loc) throws the exception.
> 
> ```
> int index = pickIndex();
> for (int i = 0; i < activeShards.size(); i++) {
> int loc = (index + i) % activeShards.size();
> 
> ```
> 
> If it's a bug, I'll file an issue.
> 
> Best regards,  
> shinsuke

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a9eaa0a8-46a7-42d7-8c74-00296741e061%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a9eaa0a8-46a7-42d7-8c74-00296741e061%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Shinsuke\_Sugaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shinsuke_sugaya/32/1208_2.png) [@Shinsuke\_Sugaya](https://discuss.elastic.co/u/Shinsuke_Sugaya)\
**Post date:** [March 26, 2014, 8:40pm UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599/6 "2014-03-26T20:40:26Z")

</div>

Thank you for the investigation and filing it.

Regards,  
shinsuke

On Thursday, March 27, 2014 12:55:56 AM UTC+9, simonw wrote:

> I opened an issue for this:  
> [IndexShardRoutingTable might barf if it has handled lots of searches... · Issue #5559 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/5559)
> 
> On Wednesday, March 26, 2014 5:53:15 AM UTC+1, Shinsuke Sugaya wrote:
> 
> > Hi
> > 
> > I encountered the following problem:
> > 
> > Caused by: java.lang.IndexOutOfBoundsException: index (-2) must not be  
> > negative  
> > at  
> > org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:306)  
> > at  
> > org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:285)  
> > at  
> > org.elasticsearch.common.collect.RegularImmutableList.get(RegularImmutableList.java:65)  
> > at  
> > org.elasticsearch.cluster.routing.IndexShardRoutingTable.preferNodeActiveInitializingShardsIt(IndexShardRoutingTable.java:378)  
> > at  
> > org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.preferenceActiveShardIterator(PlainOperationRouting.java:210)  
> > at  
> > org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.getShards(PlainOperationRouting.java:80)  
> > at  
> > org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:80)  
> > at  
> > org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:42)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:121)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:97)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:74)  
> > at  
> > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:49)  
> > at  
> > org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:63)  
> > at  
> > org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:49)  
> > at  
> > org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:85)  
> > at  
> > org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:174)  
> > ... 9 more
> > 
> > My environment is:
> > 
> > - Elasticserach 0.90.7
> > - 3 nodes in a cluster
> > - Send GET request with preference=\_local
> > 
> > Looking into IndexShardRoutingTable class, it seems that "loc" is  
> > an unexpected negative value at the following code. pickIndex method  
> > returns a value of "counter"(incremental value). If "counter" achieves  
> > Integer.MAX\_VALUE, I think that "loc" is negative and then  
> > activeShards.get(loc) throws the exception.
> > 
> > ```
> > int index = pickIndex();
> > for (int i = 0; i < activeShards.size(); i++) {
> > int loc = (index + i) % activeShards.size();
> > 
> > ```
> > 
> > If it's a bug, I'll file an issue.
> > 
> > Best regards,  
> > shinsuke

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c33bc0fe-c628-438d-b1a5-9397a2e92b96%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c33bc0fe-c628-438d-b1a5-9397a2e92b96%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [March 27, 2014, 1:46pm UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599/7 "2014-03-27T13:46:36Z")

</div>

I have to thank you for bringing it up! 🙂

On Wednesday, March 26, 2014 9:40:26 PM UTC+1, Shinsuke Sugaya wrote:

> Thank you for the investigation and filing it.
> 
> Regards,  
> shinsuke
> 
> On Thursday, March 27, 2014 12:55:56 AM UTC+9, simonw wrote:
> 
> > I opened an issue for this:  
> > [IndexShardRoutingTable might barf if it has handled lots of searches... · Issue #5559 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/5559)
> > 
> > On Wednesday, March 26, 2014 5:53:15 AM UTC+1, Shinsuke Sugaya wrote:
> > 
> > > Hi
> > > 
> > > I encountered the following problem:
> > > 
> > > Caused by: java.lang.IndexOutOfBoundsException: index (-2) must not be  
> > > negative  
> > > at  
> > > org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:306)  
> > > at  
> > > org.elasticsearch.common.base.Preconditions.checkElementIndex(Preconditions.java:285)  
> > > at  
> > > org.elasticsearch.common.collect.RegularImmutableList.get(RegularImmutableList.java:65)  
> > > at  
> > > org.elasticsearch.cluster.routing.IndexShardRoutingTable.preferNodeActiveInitializingShardsIt(IndexShardRoutingTable.java:378)  
> > > at  
> > > org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.preferenceActiveShardIterator(PlainOperationRouting.java:210)  
> > > at  
> > > org.elasticsearch.cluster.routing.operation.plain.PlainOperationRouting.getShards(PlainOperationRouting.java:80)  
> > > at  
> > > org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:80)  
> > > at  
> > > org.elasticsearch.action.get.TransportGetAction.shards(TransportGetAction.java:42)  
> > > at  
> > > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:121)  
> > > at  
> > > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$AsyncSingleAction.(TransportShardSingleOperationAction.java:97)  
> > > at  
> > > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:74)  
> > > at  
> > > org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction.doExecute(TransportShardSingleOperationAction.java:49)  
> > > at  
> > > org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:63)  
> > > at  
> > > org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:49)  
> > > at  
> > > org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:85)  
> > > at  
> > > org.elasticsearch.client.support.AbstractClient.get(AbstractClient.java:174)  
> > > ... 9 more
> > > 
> > > My environment is:
> > > 
> > > - Elasticserach 0.90.7
> > > - 3 nodes in a cluster
> > > - Send GET request with preference=\_local
> > > 
> > > Looking into IndexShardRoutingTable class, it seems that "loc" is  
> > > an unexpected negative value at the following code. pickIndex method  
> > > returns a value of "counter"(incremental value). If "counter" achieves  
> > > Integer.MAX\_VALUE, I think that "loc" is negative and then  
> > > activeShards.get(loc) throws the exception.
> > > 
> > > ```
> > > int index = pickIndex();
> > > for (int i = 0; i < activeShards.size(); i++) {
> > > int loc = (index + i) % activeShards.size();
> > > 
> > > ```
> > > 
> > > If it's a bug, I'll file an issue.
> > > 
> > > Best regards,  
> > > shinsuke

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/eb9d97f0-859d-42c0-84c4-33fdb63c69e7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/eb9d97f0-859d-42c0-84c4-33fdb63c69e7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:40am UTC](https://discuss.elastic.co/t/indexoutofboundsexception-at-indexshardroutingtable-class/16599/8 "2017-07-06T01:40:12Z")

</div>


