# Indexing problem: java.lang.ArrayIndexOutOfBoundsException: -48

**URL:** <https://discuss.elastic.co/t/indexing-problem-java-lang-arrayindexoutofboundsexception-48/4786>\
**Category:** Elasticsearch\
**Created:** [July 6, 2011, 7:36am UTC](https://discuss.elastic.co/t/indexing-problem-java-lang-arrayindexoutofboundsexception-48/4786 "2011-07-06T07:36:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marek\_Skorek](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Marek\_Skorek](https://discuss.elastic.co/u/Marek_Skorek)\
**Post date:** [July 6, 2011, 7:36am UTC](https://discuss.elastic.co/t/indexing-problem-java-lang-arrayindexoutofboundsexception-48/4786/1 "2011-07-06T07:36:10Z")

</div>

Hi again.  
While indexing my documents the following problem occured:

[2011-07-06 05:34:33,187][DEBUG][action.bulk] [Astra]  
[201009][4]: Failed to execute bulk item (index) [index {[201009]  
[message][211d779c-4e6c-4f9b-b74e-5cc502854732], source[{"messageId":  
["211d779c-4e6c-4f9b-b74e-5cc502854732"],"sourceEndpoint":["81940f97-  
e84c-42f8-b215-3809d08d69d8"],"destinationEndpoint":  
["EA217E80-2CE4-11DA-8F53-5BDB61D1C73E"],"dateCreated":"2010-09-24T01:30:31.305Z","messageState":  
[20],"documentId":["FV/13025/10/KARCZ01"],"messageType":[7]}]}]  
java.lang.ArrayIndexOutOfBoundsException: -48  
at  
org.elasticsearch.index.engine.robin.RobinEngine.dirtyLock(RobinEngine.java:  
948)  
at  
org.elasticsearch.index.engine.robin.RobinEngine.innerIndex(RobinEngine.java:  
388)  
at  
org.elasticsearch.index.engine.robin.RobinEngine.index(RobinEngine.java:  
374)  
at  
org.elasticsearch.index.shard.service.InternalIndexShard.index(InternalIndexShard.java:  
292)  
at  
org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:  
131)  
at  
org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:  
418)  
at  
org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
$AsyncShardOperationAction.access  
$100(TransportShardReplicationOperationAction.java:233)  
at  
org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction  
$AsyncShardOperationAction  
$1.run(TransportShardReplicationOperationAction.java:331)  
at java.util.concurrent.ThreadPoolExecutor  
$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor  
$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)

That happens for only one document. Any idea why I happened?

The doc seems to be visible using:  
curl -XGET 172.17.0.223:9200/201009/message/211d779c-4e6c-4f9b-  
b74e-5cc502854732?pretty=1  
{  
"\_index" : "201009",  
"\_type" : "message",  
"\_id" : "211d779c-4e6c-4f9b-b74e-5cc502854732"  
}

But it is not visible by \_search.

Anyway, is there any possibility to know about this exception on the  
client side?  
Invoking BulkResponse#hasFailures() will be enought in case on some  
problems on the server side?

---

<div class="post-metadata">

**Author:** ![Marek\_Skorek](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Marek\_Skorek](https://discuss.elastic.co/u/Marek_Skorek)\
**Post date:** [July 6, 2011, 8:35am UTC](https://discuss.elastic.co/t/indexing-problem-java-lang-arrayindexoutofboundsexception-48/4786/2 "2011-07-06T08:35:40Z")

</div>

Ok, it seems to be a bug in ES 0.16.2 (unfortulately)

Simple use case shows that it is true:

curl -XPUT localhost:9200/test/message/211d779c-4e6c-4f9b-  
b74e-5cc502854732 -d '  
{  
"test":"test"  
}'

{"error":"ArrayIndexOutOfBoundsException[-48]","status":500}

curl -XPUT localhost:9200/test/message1/211d779c-4e6c-4f9b-  
b74e-5cc502854732 -d '  
{  
"test":"test"  
}'

Changing index type name or key makes the index to be properly  
persist.

curl -XPUT localhost:9200/test/message1/211d779c-4e6c-4f9b-  
b74e-5cc502854732 -d '  
{  
"test":"test"  
}'  
{"ok":true,"\_index":"test","\_type":"message1","\_id":"211d779c-4e6c-4f9b-  
b74e-5cc502854732","\_version":2}

curl -XPUT localhost:9200/test/message/211d779c-4e6c-4f9b-  
b74e-5cc502854731 -d '  
{  
"test":"test"  
}'  
{"ok":true,"\_index":"test","\_type":"message","\_id":"211d779c-4e6c-4f9b-  
b74e-5cc502854731","\_version":2}

The problematic line is:  
return dirtyLocks[Math.abs(uid.hashCode()) % dirtyLocks.length];

So when uid.hashCode() returns Integer.MIN\_VALUE then this negative  
value is returned. Which means that modulo also returns negative value  
(wrong).

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 6, 2011, 3:58pm UTC](https://discuss.elastic.co/t/indexing-problem-java-lang-arrayindexoutofboundsexception-48/4786/3 "2011-07-06T15:58:06Z")

</div>

yea :), pushed a fix for master, will backport to 0.16 branch as well...

On Wednesday, July 6, 2011 at 11:35 AM, scoro wrote:

> Ok, it seems to be a bug in ES 0.16.2 (unfortulately)
> 
> Simple use case shows that it is true:
> 
> curl -XPUT localhost:9200/test/message/211d779c-4e6c-4f9b-  
> b74e-5cc502854732 -d '  
> {  
> "test":"test"  
> }'
> 
> {"error":"ArrayIndexOutOfBoundsException[-48]","status":500}
> 
> curl -XPUT localhost:9200/test/message1/211d779c-4e6c-4f9b-  
> b74e-5cc502854732 -d '  
> {  
> "test":"test"  
> }'
> 
> Changing index type name or key makes the index to be properly  
> persist.
> 
> curl -XPUT localhost:9200/test/message1/211d779c-4e6c-4f9b-  
> b74e-5cc502854732 -d '  
> {  
> "test":"test"  
> }'  
> {"ok":true,"\_index":"test","\_type":"message1","\_id":"211d779c-4e6c-4f9b-  
> b74e-5cc502854732","\_version":2}
> 
> curl -XPUT localhost:9200/test/message/211d779c-4e6c-4f9b-  
> b74e-5cc502854731 -d '  
> {  
> "test":"test"  
> }'  
> {"ok":true,"\_index":"test","\_type":"message","\_id":"211d779c-4e6c-4f9b-  
> b74e-5cc502854731","\_version":2}
> 
> The problematic line is:  
> return dirtyLocks[Math.abs(uid.hashCode()) % dirtyLocks.length];
> 
> So when uid.hashCode() returns Integer.MIN\_VALUE then this negative  
> value is returned. Which means that modulo also returns negative value  
> (wrong).

---

<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, 4:01am UTC](https://discuss.elastic.co/t/indexing-problem-java-lang-arrayindexoutofboundsexception-48/4786/4 "2017-07-06T04:01:37Z")

</div>


