[
https://issues.apache.org/jira/browse/LUCENE-4391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13457040#comment-13457040
]
Adrien Grand commented on LUCENE-4391:
--------------------------------------
The reason I used a {{delegate()}} method is that setting the delegate in the
constructor seems to generate cyclic dependencies when used in combination with
{{Codec.forName}}. (For example, if I use {{super("Appending",
Codec.forName("Lucene40"));}} in AppendingCodec's constructor, I get a:
{noformat}
[junit4:junit4] > Throwable #1: java.util.ServiceConfigurationError: Cannot
instantiate SPI class: org.apache.lucene.codecs.appending.AppendingCodec
[junit4:junit4] > at
org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:72)
[junit4:junit4] > at
org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:42)
[junit4:junit4] > at
org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:37)
[junit4:junit4] > at
org.apache.lucene.codecs.Codec.<clinit>(Codec.java:39)
[junit4:junit4] > at
org.apache.lucene.util.TestRuleSetupAndRestoreClassEnv.before(TestRuleSetupAndRestoreClassEnv.java:133)
[junit4:junit4] > at
org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:44)
[junit4:junit4] > at
org.apache.lucene.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:42)
[junit4:junit4] > at
com.carrotsearch.randomizedtesting.rules.SystemPropertiesInvariantRule$1.evaluate(SystemPropertiesInvariantRule.java:55)
[junit4:junit4] > at
com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:39)
[junit4:junit4] > at
com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:39)
[junit4:junit4] > at
com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
[junit4:junit4] > at
org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:43)
[junit4:junit4] > at
org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:48)
[junit4:junit4] > at
org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:70)
[junit4:junit4] > at
org.apache.lucene.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:55)
[junit4:junit4] > at
com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
[junit4:junit4] > at
com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:358)
[junit4:junit4] > at java.lang.Thread.run(Thread.java:722)
[junit4:junit4] > Caused by: java.lang.NullPointerException
[junit4:junit4] > at org.apache.lucene.codecs.Codec.forName(Codec.java:89)
[junit4:junit4] > at
org.apache.lucene.codecs.appending.AppendingCodec.<init>(AppendingCodec.java:35)
[junit4:junit4] > at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[junit4:junit4] > at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
[junit4:junit4] > at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[junit4:junit4] > at
java.lang.reflect.Constructor.newInstance(Constructor.java:525)
[junit4:junit4] > at java.lang.Class.newInstance0(Class.java:372)
[junit4:junit4] > at java.lang.Class.newInstance(Class.java:325)
[junit4:junit4] > at
org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:62)
[junit4:junit4] > ... 17 more
{noformat})
So I thought it would be less error-prone to let users specify the delegate
through an abstract method?
> Lucene40Codec methods should be final
> -------------------------------------
>
> Key: LUCENE-4391
> URL: https://issues.apache.org/jira/browse/LUCENE-4391
> Project: Lucene - Core
> Issue Type: Bug
> Reporter: Adrien Grand
> Assignee: Adrien Grand
> Fix For: 4.0
>
> Attachments: LUCENE-4391.patch
>
>
> I think all methods but {{getPostingsFormatForField}} should be made final so
> that users can't create a Codec that redefines any of the formats of Lucene40
> by subclassing (since the codec name can't be overriden by subclassing,
> Lucene will fail at loading segments that use such codecs).
--
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: [email protected]
For additional commands, e-mail: [email protected]