lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael McCandless" <luc...@mikemccandless.com>
Subject Re: norms(String field, byte[] bytes, int offset)
Date Sun, 07 Oct 2007 11:47:53 GMT

I think the intention of that method is to load all norms for that reader
into the byte array, so I think it's reasonable that an exception is
thrown if you provide a byte array that's too small.

Though maybe it would be friendlier to throw an IllegalArgumentException
that says "the byte array is not long enough"?

Mike

"Karl Wettin" <karl.wettin@gmail.com> wrote:
> I'm confused by this method. Why is the length set to maxDoc() and  
> not bytes.length? This means that the following snippet will throw an  
> ArrayIndexOutOfBoundsException in most cases:
> 
> byte[] b = new byte[1];
> ir.norms(field, b, doc);
> 
> 
> >   /** Read norms into a pre-allocated array. */
> >   public synchronized void norms(String field, byte[] bytes, int  
> > offset)
> >     throws IOException {
> >
> >     ensureOpen();
> >     Norm norm = (Norm) norms.get(field);
> >     if (norm == null) {
> >       System.arraycopy(fakeNorms(), 0, bytes, offset, maxDoc());
> >       return;
> >     }
> >
> >     if (norm.bytes != null) {                     // can copy from  
> > cache
> >       System.arraycopy(norm.bytes, 0, bytes, offset, maxDoc());
> >       return;
> >     }
> >
> >     // Read from disk.  norm.in may be shared across  multiple  
> > norms and
> >     // should only be used in a synchronized context.
> >     norm.in.seek(norm.normSeek);
> >     norm.in.readBytes(bytes, offset, maxDoc());
> >   }
> 
> -- 
> karl
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message