You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Andreas Kohn (JIRA)" <ji...@apache.org> on 2008/10/30 10:15:44 UTC

[jira] Created: (LUCENE-1431) NullPointerException in CloseableThreadLocal#get() if CTL is closed

NullPointerException in CloseableThreadLocal#get() if CTL is closed
-------------------------------------------------------------------

                 Key: LUCENE-1431
                 URL: https://issues.apache.org/jira/browse/LUCENE-1431
             Project: Lucene - Java
          Issue Type: Bug
          Components: Other
    Affects Versions: 2.4
         Environment: Linux Fedora 9, amd64, Sun JDK 1.6.0_03 amd64
            Reporter: Andreas Kohn
         Attachments: LUCENE-1431.diff

Pretty simple NPE, happening because some thread closed the CloseableThreadLocal, but another place still wanted to look at it:

{noformat}
 java.lang.NullPointerException
     at org.apache.lucene.util.CloseableThreadLocal.get(Unknown Source)
     at org.apache.lucene.index.TermInfosReader.getThreadResources(Unknown Source)
     at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
     at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
     at org.apache.lucene.index.SegmentTermDocs.seek(Unknown Source)
     at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.termDocs(Unknown Source)
     at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.next(Unknown Source)
{noformat}

I believe the attached patch should fix those.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Resolved: (LUCENE-1431) NullPointerException in CloseableThreadLocal#get() if CTL is closed

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-1431?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael McCandless resolved LUCENE-1431.
----------------------------------------

       Resolution: Invalid
    Lucene Fields: [New, Patch Available]  (was: [Patch Available, New])

OK thanks!

> NullPointerException in CloseableThreadLocal#get() if CTL is closed
> -------------------------------------------------------------------
>
>                 Key: LUCENE-1431
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1431
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 2.4
>         Environment: Linux Fedora 9, amd64, Sun JDK 1.6.0_03 amd64
>            Reporter: Andreas Kohn
>         Attachments: LUCENE-1431.diff
>
>
> Pretty simple NPE, happening because some thread closed the CloseableThreadLocal, but another place still wanted to look at it:
> {noformat}
>  java.lang.NullPointerException
>      at org.apache.lucene.util.CloseableThreadLocal.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.getThreadResources(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.SegmentTermDocs.seek(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.termDocs(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.next(Unknown Source)
> {noformat}
> I believe the attached patch should fix those.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (LUCENE-1431) NullPointerException in CloseableThreadLocal#get() if CTL is closed

Posted by "Andreas Kohn (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-1431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12644675#action_12644675 ] 

Andreas Kohn commented on LUCENE-1431:
--------------------------------------

We reworked the code around the problematic area (not using incRef/decRef, but instead preventing the updating from running using internal existing locks), so I think this issue can be closed and just serve as reference.

Thanks!

> NullPointerException in CloseableThreadLocal#get() if CTL is closed
> -------------------------------------------------------------------
>
>                 Key: LUCENE-1431
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1431
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 2.4
>         Environment: Linux Fedora 9, amd64, Sun JDK 1.6.0_03 amd64
>            Reporter: Andreas Kohn
>         Attachments: LUCENE-1431.diff
>
>
> Pretty simple NPE, happening because some thread closed the CloseableThreadLocal, but another place still wanted to look at it:
> {noformat}
>  java.lang.NullPointerException
>      at org.apache.lucene.util.CloseableThreadLocal.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.getThreadResources(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.SegmentTermDocs.seek(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.termDocs(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.next(Unknown Source)
> {noformat}
> I believe the attached patch should fix those.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (LUCENE-1431) NullPointerException in CloseableThreadLocal#get() if CTL is closed

Posted by "Andreas Kohn (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-1431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12643796#action_12643796 ] 

Andreas Kohn commented on LUCENE-1431:
--------------------------------------

Continueing reading application and lucene code, the patch will only move the NPE to a few lines later when TermInfosReaders#getThreadResources() tries to call CloseableThreadLocal#set() with the newly created resources.

A bit more context on the application where I hit this problem:
This is a web application that runs a periodic update check that will create new readers on a newer indices (no reopen, real creation of the readers), and close the older ones. Requests will get the currently open reader, and generally handle the case where this gets closed by catching the exceptions and doing "something sensible".
The exception is hit in a place that is implementing a Filter, and expects an IOException if the reader is closed by chance.
With lucene 2.3.2, this worked nicely, but with 2.4.0 we get the above exception, instead of the expected IOException.

I see that there is now IndexReader#incRef() and IndexReader#decRef(), so I'll play with those methods to prevent "early" closing of readers, and avoid handling the exceptions. 


The question still remains whether CloseableThreadLocal should somehow handle the 'closed' state in get()/set(), or whether documentation should be added that close() really means nothing else will work after that.


> NullPointerException in CloseableThreadLocal#get() if CTL is closed
> -------------------------------------------------------------------
>
>                 Key: LUCENE-1431
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1431
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 2.4
>         Environment: Linux Fedora 9, amd64, Sun JDK 1.6.0_03 amd64
>            Reporter: Andreas Kohn
>         Attachments: LUCENE-1431.diff
>
>
> Pretty simple NPE, happening because some thread closed the CloseableThreadLocal, but another place still wanted to look at it:
> {noformat}
>  java.lang.NullPointerException
>      at org.apache.lucene.util.CloseableThreadLocal.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.getThreadResources(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.SegmentTermDocs.seek(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.termDocs(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.next(Unknown Source)
> {noformat}
> I believe the attached patch should fix those.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Updated: (LUCENE-1431) NullPointerException in CloseableThreadLocal#get() if CTL is closed

Posted by "Andreas Kohn (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-1431?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Kohn updated LUCENE-1431:
---------------------------------

    Attachment: LUCENE-1431.diff

> NullPointerException in CloseableThreadLocal#get() if CTL is closed
> -------------------------------------------------------------------
>
>                 Key: LUCENE-1431
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1431
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 2.4
>         Environment: Linux Fedora 9, amd64, Sun JDK 1.6.0_03 amd64
>            Reporter: Andreas Kohn
>         Attachments: LUCENE-1431.diff
>
>
> Pretty simple NPE, happening because some thread closed the CloseableThreadLocal, but another place still wanted to look at it:
> {noformat}
>  java.lang.NullPointerException
>      at org.apache.lucene.util.CloseableThreadLocal.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.getThreadResources(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.SegmentTermDocs.seek(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.termDocs(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.next(Unknown Source)
> {noformat}
> I believe the attached patch should fix those.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


[jira] Commented: (LUCENE-1431) NullPointerException in CloseableThreadLocal#get() if CTL is closed

Posted by "Michael McCandless (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-1431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12643804#action_12643804 ] 

Michael McCandless commented on LUCENE-1431:
--------------------------------------------

OK, so you were continuing to use a TermDocs after its reader had been closed.

Unfortunately, Lucene doesn't and can't really guarantee you'll always get a nice AlreadyClosedException in all possible places where you use a reader after closing it, because inserting that check could be a performance hit.

So what happens (NPE or IOE etc.) is intentionally not defined/guaranteed, though we will in general make a "best effort" to throw an AlreadyClosedException when possible.

In this particular case I don't see an obvious place to insert an ensureOpen() call without risking a performance hit.

incRef/decRef should solve this nicely.

> NullPointerException in CloseableThreadLocal#get() if CTL is closed
> -------------------------------------------------------------------
>
>                 Key: LUCENE-1431
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1431
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 2.4
>         Environment: Linux Fedora 9, amd64, Sun JDK 1.6.0_03 amd64
>            Reporter: Andreas Kohn
>         Attachments: LUCENE-1431.diff
>
>
> Pretty simple NPE, happening because some thread closed the CloseableThreadLocal, but another place still wanted to look at it:
> {noformat}
>  java.lang.NullPointerException
>      at org.apache.lucene.util.CloseableThreadLocal.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.getThreadResources(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.TermInfosReader.get(Unknown Source)
>      at org.apache.lucene.index.SegmentTermDocs.seek(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.termDocs(Unknown Source)
>      at org.apache.lucene.index.MultiSegmentReader$MultiTermDocs.next(Unknown Source)
> {noformat}
> I believe the attached patch should fix those.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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