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

Uwe Schindler edited comment on LUCENE-10341 at 12/26/21, 12:34 PM:
--------------------------------------------------------------------

OK, I verified everything:
- Class#forName is caller-sensitive but you are always allowed to load classes 
from any module you have access permitted by secruity manager (also 
non-exported ones): "Note that this method does not check whether the requested 
class is accessible to its caller."
- Constructor#newInstance(...) is caller-sensitive, but it only checks in 
module mode that the class is in an exported package. It does not check if the 
class' module is required by the caller (see 
{{jdk.internal.reflect.Reflection.verifyMemberAccess(Class<?>, Class<?>, 
Class<?>, int)}}. Without that our own SPI implementation for attributes won't 
work, too - it also uses newInstance()

So all should be fine, reopen if there are more problems.


was (Author: thetaphi):
OK, I verified everything:
- Class#forName is caller-sensitive but you are always allowed to load classes 
from any module you have access permitted by secruity manager (also 
non-exported ones): "Note that this method does not check whether the requested 
class is accessible to its caller."
- Constructor#newInstance(...) is caller-sensitive, but it only checks in 
module mode that the class is in an exported package. It does not check if the 
class' module is required by the caller. Without that our own SPI 
implementation for attributes won't work, too - it also uses newInstance()

So all should be fine, reopen if there are more problems.

> 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
>            Assignee: Uwe Schindler
>            Priority: Major
>
> {{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