Java Mailing List Archive

http://www.java2.5341.com/

Home » java-user.lucene »

Re: ClassCastException when writing to index writer

Paul Chan

2008-10-03

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi Mike,

I am actually using the Compass Search Engine which in turn makes use of
Lucene. They are doing the following in their code:

    IndexWriter indexWriter = new IndexWriter(dir, autoCommit, analyzer,
create, deletionPolicy);

where autoCommit = false.

In turn, Lucene will do the following:

public class IndexWriter {

   public IndexWriter(Directory d, boolean autoCommit, Analyzer a,
boolean create, IndexDeletionPolicy deletionPolicy)
    throws CorruptIndexException, LockObtainFailedException, IOException
{
      init(d, a, create, false, deletionPolicy, autoCommit);
   }

   private void init(Directory d, Analyzer a, final boolean create,
boolean closeDir,             IndexDeletionPolicy deletionPolicy,
boolean autoCommit)
   {
     ...
     ..
     if (!autoCommit) {
      rollbackSegmentInfos = (SegmentInfos) segmentInfos.clone();
     }
   }
}

which calls the clone() method that causes the exception because autoCommit
= false.

On Fri, Oct 3, 2008 at 4:54 PM, Michael McCandless <
lucene@(protected):

>
> Can you describe what led up to this exception? Ie, what calls you made to
> Lucene before this.
>
> Mike
>
>
> Paul Chan wrote:
>
> I think I know what the problem is looking at the code:
>>
>> In SegmentInfos.java (line 321):
>>
>> class SegmentInfos extends Vector
>> {
>>  public Object clone() {
>>    SegmentInfos sis = (SegmentInfos) super.clone();
>>    for(int i=0;i<sis.size();i++) {
>>     sis.setElementAt(((SegmentInfo) sis.elementAt(i)).clone(), i);
>>    }
>>    return sis;
>>  }
>> }
>>
>> We see that it is trying to cast a Vector into SegmentInfos which explains
>> the ClassCastException. This is definitely a bug.
>>
>>
>> On Fri, Oct 3, 2008 at 3:40 PM, Paul Chan <wayofdragon@(protected):
>>
>> Hi,
>>>
>>> I am using lucene 2.3.2 and I encounter the following exception when I
>>> try
>>> to insert a object into the index.
>>>
>>> Caused by: java.lang.ClassCastException: java.util.Vector cannot be cast
>>> to
>>> org.apache.lucene.index.SegmentInfos
>>> at org.apache.lucene.index.SegmentInfos.clone (SegmentInfos.java:321)
>>> at org.apache.lucene.index.IndexWriter.init (IndexWriter.java:715)
>>> at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:666)
>>>
>>> Has Anyone seen this problem before? What seems to be the problem?
>>>
>>> Thanks!
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@(protected)
> For additional commands, e-mail: java-user-help@(protected)
>
>
©2008 java2.5341.com - Jax Systems, LLC, U.S.A.