Skip to content

Commit b8dcbc4

Browse files
committed
java.lang.ArrayIndexOutOfBoundsException when indexing a doc, closes elastic#1094.
1 parent 35a82b6 commit b8dcbc4

File tree

1 file changed

+12
-3
lines changed
  • modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin

1 file changed

+12
-3
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
package org.elasticsearch.index.engine.robin;
2121

22-
import org.apache.lucene.index.*;
22+
import org.apache.lucene.index.ExtendedIndexSearcher;
23+
import org.apache.lucene.index.IndexReader;
24+
import org.apache.lucene.index.IndexWriter;
25+
import org.apache.lucene.index.IndexWriterConfig;
26+
import org.apache.lucene.index.Term;
2327
import org.apache.lucene.store.AlreadyClosedException;
2428
import org.apache.lucene.util.UnicodeUtil;
2529
import org.elasticsearch.ElasticSearchException;
@@ -581,7 +585,7 @@ private void innerDelete(Delete delete, IndexWriter writer) throws IOException {
581585

582586
@Override public Searcher searcher() throws EngineException {
583587
AcquirableResource<ReaderSearcherHolder> holder;
584-
for (; ;) {
588+
for (; ; ) {
585589
holder = this.nrtResource;
586590
if (holder.acquire()) {
587591
break;
@@ -945,7 +949,12 @@ private void innerClose() {
945949
}
946950

947951
private Object dirtyLock(Term uid) {
948-
return dirtyLocks[Math.abs(uid.hashCode()) % dirtyLocks.length];
952+
int hash = uid.text().hashCode();
953+
// abs returns Integer.MIN_VALUE, so we need to protect against it...
954+
if (hash == Integer.MIN_VALUE) {
955+
hash = 0;
956+
}
957+
return dirtyLocks[Math.abs(hash) % dirtyLocks.length];
949958
}
950959

951960
private long loadCurrentVersionFromIndex(Term uid) {

0 commit comments

Comments
 (0)