[ 
https://issues.apache.org/jira/browse/LUCENE-5218?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13777584#comment-13777584
 ] 

Littlestar edited comment on LUCENE-5218 at 9/25/13 3:02 PM:
-------------------------------------------------------------

{noformat}
public void fillSlice(BytesRef b, long start, int length) {
      assert length >= 0: "length=" + length;
      assert length <= blockSize+1;
      final int index = (int) (start >> blockBits);
      final int offset = (int) (start & blockMask);
      b.length = length;
      if (blockSize - offset >= length) {
        // Within block
        b.bytes = blocks[index];  //here is 
java.lang.ArrayIndexOutOfBoundsException
        b.offset = offset;
      } else {
        // Split
        b.bytes = new byte[length];
        b.offset = 0;
        System.arraycopy(blocks[index], offset, b.bytes, 0, blockSize-offset);
        System.arraycopy(blocks[1+index], 0, b.bytes, blockSize-offset, 
length-(blockSize-offset));
      }
    }
{noformat}

I debug into above code.
when java.lang.ArrayIndexOutOfBoundsException occurs:
b=[], start=131072,lenth=0
index=2, offset=0, blockSize=65536, blocks.length=2

my patch:
{noformat}
 public void fillSlice(BytesRef b, long start, int length) {
      assert length >= 0: "length=" + length;
      assert length <= blockSize+1: "length=" + length;
      final int index = (int) (start >> blockBits);
      final int offset = (int) (start & blockMask);
      b.length = length;
      
      +if (index >= blocks.length) {
      +   // Outside block
      +   b.bytes = EMPTY_BYTES;
      +   b.offset = b.length = 0;
      +} else if (blockSize - offset >= length) {
        // Within block
        b.bytes = blocks[index];
        b.offset = offset;
      } else {
        // Split
        b.bytes = new byte[length];
        b.offset = 0;
        System.arraycopy(blocks[index], offset, b.bytes, 0, blockSize-offset);
        System.arraycopy(blocks[1+index], 0, b.bytes, blockSize-offset, 
length-(blockSize-offset));
      }
    }

{noformat}
                
      was (Author: cnstar9988):
    {noformat}
public void fillSlice(BytesRef b, long start, int length) {
      assert length >= 0: "length=" + length;
      assert length <= blockSize+1;
      final int index = (int) (start >> blockBits);
      final int offset = (int) (start & blockMask);
      b.length = length;
      if (blockSize - offset >= length) {
        // Within block
        b.bytes = blocks[index];  //here is 
java.lang.ArrayIndexOutOfBoundsException
        b.offset = offset;
      } else {
        // Split
        b.bytes = new byte[length];
        b.offset = 0;
        System.arraycopy(blocks[index], offset, b.bytes, 0, blockSize-offset);
        System.arraycopy(blocks[1+index], 0, b.bytes, blockSize-offset, 
length-(blockSize-offset));
      }
    }
{noformat}

I debug into above code.
when java.lang.ArrayIndexOutOfBoundsException occurs:
b=[], start=131072,lenth=0
index=2, offset=0, blocks.length=2

my patch:
{noformat}
 public void fillSlice(BytesRef b, long start, int length) {
      assert length >= 0: "length=" + length;
      assert length <= blockSize+1: "length=" + length;
      final int index = (int) (start >> blockBits);
      final int offset = (int) (start & blockMask);
      b.length = length;
      
      +if (index >= blocks.length) {
      +   // Outside block
      +   b.bytes = EMPTY_BYTES;
      +   b.offset = b.length = 0;
      +} else if (blockSize - offset >= length) {
        // Within block
        b.bytes = blocks[index];
        b.offset = offset;
      } else {
        // Split
        b.bytes = new byte[length];
        b.offset = 0;
        System.arraycopy(blocks[index], offset, b.bytes, 0, blockSize-offset);
        System.arraycopy(blocks[1+index], 0, b.bytes, blockSize-offset, 
length-(blockSize-offset));
      }
    }

{noformat}
                  
> background merge hit exception && Caused by: 
> java.lang.ArrayIndexOutOfBoundsException
> -------------------------------------------------------------------------------------
>
>                 Key: LUCENE-5218
>                 URL: https://issues.apache.org/jira/browse/LUCENE-5218
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: core/index
>    Affects Versions: 4.4
>         Environment: Linux MMapDirectory.
>            Reporter: Littlestar
>         Attachments: lucene44-LUCENE-5218.zip
>
>
> forceMerge(80)
> ==============================
> Caused by: java.io.IOException: background merge hit exception: 
> _3h(4.4):c79921/2994 _3vs(4.4):c38658 _eq(4.4):c38586 _h1(4.4):c37370 
> _16k(4.4):c36591 _j4(4.4):c34316 _dx(4.4):c30550 _3m6(4.4):c30058 
> _dl(4.4):c28440 _d8(4.4):c19599 _dy(4.4):c1500/75 _h2(4.4):c1500 into _3vt 
> [maxNumSegments=80]
>       at org.apache.lucene.index.IndexWriter.forceMerge(IndexWriter.java:1714)
>       at org.apache.lucene.index.IndexWriter.forceMerge(IndexWriter.java:1650)
>       at 
> com.xxx.yyy.engine.lucene.LuceneEngine.flushAndReopen(LuceneEngine.java:1295)
>       ... 4 more
> Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
>       at 
> org.apache.lucene.util.PagedBytes$Reader.fillSlice(PagedBytes.java:92)
>       at 
> org.apache.lucene.codecs.lucene42.Lucene42DocValuesProducer$6.get(Lucene42DocValuesProducer.java:267)
>       at 
> org.apache.lucene.codecs.DocValuesConsumer$2$1.setNext(DocValuesConsumer.java:239)
>       at 
> org.apache.lucene.codecs.DocValuesConsumer$2$1.hasNext(DocValuesConsumer.java:201)
>       at 
> org.apache.lucene.codecs.lucene42.Lucene42DocValuesConsumer.addBinaryField(Lucene42DocValuesConsumer.java:218)
>       at 
> org.apache.lucene.codecs.perfield.PerFieldDocValuesFormat$FieldsWriter.addBinaryField(PerFieldDocValuesFormat.java:110)
>       at 
> org.apache.lucene.codecs.DocValuesConsumer.mergeBinaryField(DocValuesConsumer.java:186)
>       at 
> org.apache.lucene.index.SegmentMerger.mergeDocValues(SegmentMerger.java:171)
>       at org.apache.lucene.index.SegmentMerger.merge(SegmentMerger.java:108)
>       at 
> org.apache.lucene.index.IndexWriter.mergeMiddle(IndexWriter.java:3772)
>       at org.apache.lucene.index.IndexWriter.merge(IndexWriter.java:3376)
>       at 
> org.apache.lucene.index.ConcurrentMergeScheduler.doMerge(ConcurrentMergeScheduler.java:405)
>       at 
> org.apache.lucene.index.ConcurrentMergeScheduler$MergeThread.run(ConcurrentMergeScheduler.java:482)
> ===============

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to