lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LUCENE-4440) FilterCodec should take a delegate Codec in its ctor
Date Thu, 27 Sep 2012 14:32:09 GMT

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

Uwe Schindler commented on LUCENE-4440:
---------------------------------------

bq. Isn't there a way to ensure that NamedSPILoader would finish before forName() is accessed?

Unfortunately not, this is a chicken-and-egg problem: If you access Codec.class in any way
(e.g. already at the time when you subclass it!), it is classloaded. After classloaded, it
is initialized, so its static <clinit> method is called. This method runs new NamedSPILoader(Codec.class)
[the first line in the class source code], and this one loads all codecs which are listed
in META-INF/services. As e.g. AppendingCodec is listed there, it is loaded by NamedSPILoader
and its ctor is called. As we are still in the stacktrace inside NamedSPILoader.<init>,
this call did not yet return to caller (Codec.<clinit>), so the assignment of the static
final loader field is not yet finished. Unfortunately, AppendingCodec.<init> calls Codec.forName()
and hits the NPE, because the field is not yet initialized. You have to say: You cannot call
*any* method of Codec at that time!
                
> FilterCodec should take a delegate Codec in its ctor
> ----------------------------------------------------
>
>                 Key: LUCENE-4440
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4440
>             Project: Lucene - Core
>          Issue Type: Improvement
>          Components: core/codecs
>            Reporter: Shai Erera
>            Assignee: Shai Erera
>            Priority: Minor
>         Attachments: LUCENE-4440.patch
>
>
> FilterCodec has a delegate() method through which an extension can return its delegate
Codec. This method is called on every Codec method. Adrien, on LUCENE-4391, failed to pass
a Codec in the ctor, since he couldn't called Codec.forName().
> Instead, we should just pass e.g. new Lucene40Codec(). I'll post a patch shortly.

--
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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message