Tomoko Uchida created LUCENE-10341:
--------------------------------------

             Summary: AttributeFactory.DefaultAttributeFactory does not work on 
module mode
                 Key: LUCENE-10341
                 URL: https://issues.apache.org/jira/browse/LUCENE-10341
             Project: Lucene - Core
          Issue Type: Sub-task
            Reporter: Tomoko Uchida


{{AttributeFactory.DefaultAttributeFactory}} seems not to work on module mode.

There is a {{Class.forName()}} call that attempts to obtain classes in outside 
modules (analysis modules).
{code:java}
public static final AttributeFactory DEFAULT_ATTRIBUTE_FACTORY = new 
DefaultAttributeFactory();

  private static final class DefaultAttributeFactory extends AttributeFactory {
    private final ClassValue<MethodHandle> constructors =
        new ClassValue<MethodHandle>() {
          @Override
          protected MethodHandle computeValue(Class<?> attClass) {
            return 
findAttributeImplCtor(findImplClass(attClass.asSubclass(Attribute.class)));
          }
        };
{code}
Reproduciable code
{code:java}
// module-info
module attfactory {
  requires org.apache.lucene.core;
  requires org.apache.lucene.analysis.kuromoji;
}

// test class
package attfactory;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;

import org.apache.lucene.analysis.ja.JapaneseAnalyzer;
import org.apache.lucene.analysis.ja.tokenattributes.BaseFormAttribute;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;

public class AttributeFactoryTest {
  public static void main(String[] args) {
    Analyzer analyzer = new JapaneseAnalyzer();
    TokenStream ts = analyzer.tokenStream("", "hello, icu");
    CharTermAttribute charAtt = ts.getAttribute(CharTermAttribute.class);
    System.out.println("CharTermAttribute impl: " + 
charAtt.getClass().getName());
    BaseFormAttribute baseAtt = ts.getAttribute(BaseFormAttribute.class);
    System.out.println("BaseFormAttribute impl: " + 
baseAtt.getClass().getName());
  }
}
{code}
When running on class path mode, it works.
{code:java}
$ java -cp 
modules/attributefactory-test-1.0-SNAPSHOT.jar:modules/lucene-core-10.0.0-SNAPSHOT.jar:modules/lucene-analysis-common-10.0.0-SNAPSHOT.jar:modules/lucene-analysis-kuromoji-10.0.0-SNAPSHOT.jar
 attfactory.AttributeFactoryTest
CharTermAttribute impl: 
org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl
BaseFormAttribute impl: 
org.apache.lucene.analysis.ja.tokenattributes.BaseFormAttributeImpl
{code}
When running on module mode, {{TokenStream.getAttribute(...)}} returns null for 
custom attributes.
{code:java}
$ java --module-path modules --module attfactory/attfactory.AttributeFactoryTest
Exception in thread "main" java.lang.ExceptionInInitializerError
        at 
org.apache.lucene.analysis.kuromoji@10.0.0-SNAPSHOT/org.apache.lucene.analysis.ja.JapaneseAnalyzer.<init>(JapaneseAnalyzer.java:46)
        at 
attfactory/attfactory.AttributeFactoryTest.main(AttributeFactoryTest.java:12)
Caused by: java.lang.NullPointerException
{code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to