You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Shivani Sawhney <sh...@netedgecomputing.com> on 2006/02/16 10:05:47 UTC

RE: It worked---NullPointerException while closing the index writer

Hi,

At least the re-indexing part worked....

I just removed the finally block and the NullPointerException was solved.:
          

 if (indexwriter != null)
            {
                System.out.println("going to close index writer");
                indexwriter.close();
            }
        } catch (IOException e)
        {
            e.printStackTrace();
            throw new Error(e);
        } finally
        {
            if (indexwriter != null)
            {
                indexwriter.close();
            }
        }
    }



-----Original Message-----
From: Shivani Sawhney [mailto:shivani@netedgecomputing.com] 
Sent: 16 February, 2006 2:30 PM
To: java-user@lucene.apache.org
Subject: NullPointerException while closing the index writer

Hi,

 

I couldn't fix the problem while creating an index, so I decided to clean
all the indexes from the server and try to re-index all my documents.

 

I am getting a NullPointerException, again while closing the index writer. I
don't know what I can be doing wrong while simply creating a fresh index.

 

The error log is as follows:

 

 

2006-02-16 14:19:05,368 INFO  [STDOUT] after adding document...indexwriter
is org.apache.lucene.index.IndexWriter@157566d

2006-02-16 14:19:05,368 INFO  [STDOUT] Index written...

2006-02-16 14:19:05,368 INFO  [STDOUT] before closing, index writer is
org.apache.lucene.index.IndexWriter@157566d

2006-02-16 14:19:05,368 INFO  [STDOUT] going to close index writer

2006-02-16 14:19:05,806 WARN  [org.apache.struts.action.RequestProcessor]
Unhandled Exception thrown: class java.lang.NullPointerException

2006-02-16 14:19:05,806 ERROR [org.jboss.web.localhost.Engine]
StandardWrapperValve[action]: Servlet.service() for servlet action threw
exception

java.lang.NullPointerException

      at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:195)

      at rd.admin.NewIndexer.indexTextFile(NewIndexer.java:126)

      at rd.admin.AddResume.indexOneRow(AddResume.java:38)

      at rd.admin.LuceneGateway.buildMapAndIndex(LuceneGateway.java:46)

      at
rd.admin.CreateIndexesFromCandidateTableAction.npExecute(CreateIndexesFromCa
ndidateTableAction.java:152)

      at np.core.BaseNPAction.execute(BaseNPAction.java:116)

      at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
sor.java:421)

      at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)

      at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)

 

 

 

Any help will be much appreciated.

Regards,

Shivani

 

 

 

-----Original Message-----
From: Shivani Sawhney [mailto:shivani@netedgecomputing.com] 
Sent: 16 February, 2006 11:03 AM
To: java-user@lucene.apache.org
Subject: RE: ArrayIndexOutOfBoundsException while closing the index writer

 

Hi Otis,

 

Thanks for such a quick reply. I tried using finally, but it didn't help.

 

I guess if I explain the integration of lucene with my app in little detail

then you probably can help me better.

 

I allow users to upload documents, which are then indexed, and search on

them. Now I am getting this error when I am trying to index the document and

particularly while closing the index writer.

If we look closely at the error log, it's giving an error at 

 

org.apache.lucene.index.FieldInfos.fieldInfo(FieldInfos.java:135)

 

i.e., when lucene tries to get something by the field name, 

 

return (FieldInfo) byName.get(fieldName);

 

, now what beats me is that, indexing on fields has already been done by the

time we want to close the index writer, so how come I don't get an error

while indexing, what goes wrong when I am trying to close the index writer.

 

 

Please see if you can help me with this....

 

Thanks in advance.

 

The code used for indexing is as follows:

 

    public void indexFile(IndexWriter indexwriter, File resumeFile)

    {

        Document document = new Document();       

        try

        {            

            File afile[] = indexDirFile.listFiles();

            boolean flag = false;

 

            if (afile.length <= 0)

                flag = true;

            

            indexwriter = new IndexWriter(indexDirFile, new

StandardAnalyzer(), flag);

 

            try

            {                

                document.add(Field.Text(IndexerColumns.contents, new

FileReader(resumeFile)));

            } catch (FileNotFoundException e)

            {

                e.printStackTrace();

                throw new MyRuntimeException(e.getMessage(), e);

            }

        

        document.add(Field.Keyword( IndexerColumns.id,

String.valueOf(mapLuceneParams.get(IndexerColumns.id)) ));

 

        for (int i = 0; i < this.columnInfos.length; i++)

        {

            ColumnInfo columnInfo = columnInfos[i];

            String value =

String.valueOf(mapLuceneParams.get(columnInfo.columnName));

 

            if (value != null)

            {

                value = value.trim();

                if (value.length() != 0)

                {

                  if (columnInfo.istokenized)

                    {                    

                        document.add(Field.Text(columnInfo.columnName,

value));                        

                    } else

                    {

                        document.add(Field.Keyword(columnInfo.columnName,

value));

                    }

                }

            }

        }

        document.add(Field.Keyword(IndexerColumns.filePath,

String.valueOf(mapLuceneParams.get(IndexerColumns.filePath))));

 

        try

        {

            indexwriter.addDocument(document); 

        } catch (IOException e)

        {

            e.printStackTrace();

            throw new MyRuntimeException(e.getMessage(), e);

        } 

    

          indexwriter.close();

        } catch (IOException e)

        {   

            e.printStackTrace();

            throw new Error(e);

        }finally

        {

            if(indexwriter != null)

            {

                indexwriter.close();

            }

        }

 

 

 

Regards,

Shivani

 

 

 

 

-----Original Message-----

From: Otis Gospodnetic [mailto:otis_gospodnetic@yahoo.com] 

Sent: 16 February, 2006 10:16 AM

To: java-user@lucene.apache.org

Subject: Re: ArrayIndexOutOfBoundsException while closing the index writer

 

Who knows what else the app is doing.

However, I can quickly suggest that you add a finally block and close your

writer in there if writer != null.

 

Otis

 

----- Original Message ----

From: Shivani Sawhney <sh...@netedgecomputing.com>

To: java-user@lucene.apache.org

Sent: Wednesday, February 15, 2006 11:31:12 PM

Subject: ArrayIndexOutOfBoundsException while closing the index writer

 

Hi,

 

I have used Lucene in my application and am just indexing and searching on

some documents. The code that indexes the documents was working fine till

yesterday and suddenly stopped working.

 

I get an error when I am trying to close the index writer. The code is as

follows:

 

 

 

 

 

.

 

            IndexWriter indexwriter = new IndexWriter(indexDirFile, new

StandardAnalyzer(), flag);

 

            indexFile(indexwriter, resumeFile);

 

            indexwriter.close(); //causing errors

 

        } catch (IOException e)

 

        {   

 

            e.printStackTrace();

 

            throw new Error(e);

 

        }

 

.

 

 

 

And the error log is as follows:

 

 

 

2006-02-15 18:47:48,748 WARN  [org.apache.struts.action.RequestProcessor]

Unhandled Exception thrown: class java.lang.ArrayIndexOutOfBoundsException

 

2006-02-15 18:47:48,748 ERROR [org.jboss.web.localhost.Engine]

StandardWrapperValve[action]: Servlet.service() for servlet action threw

exception

 

java.lang.ArrayIndexOutOfBoundsException: 105 >= 25

 

            at java.util.Vector.elementAt(Vector.java:432)

 

            at

org.apache.lucene.index.FieldInfos.fieldInfo(FieldInfos.java:135)

 

            at

org.apache.lucene.index.FieldsReader.doc(FieldsReader.java:103)

 

            at

org.apache.lucene.index.SegmentReader.document(SegmentReader.java:237)

 

            at

org.apache.lucene.index.SegmentMerger.mergeFields(SegmentMerger.java:169)

 

            at

org.apache.lucene.index.SegmentMerger.merge(SegmentMerger.java:97)

 

            at

org.apache.lucene.index.IndexWriter.mergeSegments(IndexWriter.java:425)

 

            at

org.apache.lucene.index.IndexWriter.flushRamSegments(IndexWriter.java:373)

 

            at

org.apache.lucene.index.IndexWriter.close(IndexWriter.java:193)

 

            at rd.admin.NewIndexer.indexTextFile(NewIndexer.java:108)

 

            at rd.admin.AddResume.indexOneRow(AddResume.java:38)

 

            at

rd.admin.LuceneGateway.buildMapAndIndex(LuceneGateway.java:46)

 

            at rd.admin.LuceneGateway.indexResume(LuceneGateway.java:30)

 

            at

rd.admin.UploadResumeAgainstRequisition.npExecute(UploadResumeAgainstRequisi

tion.java:106)

 

            at np.core.BaseNPAction.execute(BaseNPAction.java:116)

 

            at

org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces

sor.java:421)

 

            at

org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)

 

            at

org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)

 

            at

org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)

 

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

 

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

 

            at

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application

FilterChain.java:237)

 

            at

org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh

ain.java:157)

 

            at

org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.ja

va:75)

 

            at

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application

FilterChain.java:186)

 

            at

org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh

ain.java:157)

 

            at

org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja

va:214)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:104)

 

            at

org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

 

            at

org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContext

Valve.java:198)

 

            at

org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja

va:152)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:104)

 

            at

org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalVal

ve.java:66)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:102)

 

            at

org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssoci

ationValve.java:153)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:102)

 

            at

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase

.java:540)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:102)

 

            at

org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:

54)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:102)

 

            at

org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

 

            at

org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137

)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:104)

 

            at

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118

)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:102)

 

            at

org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

 

            at

org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java

:109)

 

            at

org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContex

t.java:104)

 

            at

org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

 

            at

org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

 

            at

org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)

 

            at

org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)

 

            at

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne

ction(Http11Protocol.java:705)

 

            at

org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)

 

            at

org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav

a:683)

 

            at java.lang.Thread.run(Thread.java:595)

 

 

 

 

 

 

 

Can someone please suggest a solution or even the cause of the problem?

 

 

 

Thanks in advance.

 

 

 

Regards,

 

Shivani

 

 

 

 

 

 

 

---------------------------------------------------------------------

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

 




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