Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE for TestRandomChains.testRandomChainsWithLargeStrings #13104

Merged
merged 2 commits into from Feb 15, 2024

Conversation

easyice
Copy link
Contributor

@easyice easyice commented Feb 14, 2024

Related to LUCENE-10353

./gradlew test --tests TestRandomChains.testRandomChainsWithLargeStrings -Dtests.seed=1B915D6C476F9BFE -Dtests.nightly=true -Dtests.locale=mn -Dtests.timezone=Canada/Mountain -Dtests.asserts=true -Dtests.file.encoding=UTF-8
org.apache.lucene.analysis.tests.TestRandomChains > testRandomChainsWithLargeStrings FAILED
    java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "org.apache.lucene.analysis.tokenattributes.TypeAttribute.type()" is null
        at __randomizedtesting.SeedInfo.seed([1B915D6C476F9BFE:71CAE27D1E21BB0D]:0)
        at org.apache.lucene.analysis.common@10.0.0-SNAPSHOT/org.apache.lucene.analysis.payloads.NumericPayloadTokenFilter.incrementToken(NumericPayloadTokenFilter.java:49)
        at org.apache.lucene.analysis.common@10.0.0-SNAPSHOT/org.apache.lucene.analysis.miscellaneous.ConditionalTokenFilter.incrementToken(ConditionalTokenFilter.java:185)
        at org.apache.lucene.test_framework@10.0.0-SNAPSHOT/org.apache.lucene.tests.analysis.ValidatingTokenFilter.incrementToken(ValidatingTokenFilter.java:81)
        at org.apache.lucene.analysis.common@10.0.0-SNAPSHOT/org.apache.lucene.analysis.miscellaneous.ConditionalTokenFilter$OneTimeWrapper.incrementToken(ConditionalTokenFilter.java:65)
        at org.apache.lucene.analysis.icu@10.0.0-SNAPSHOT/org.apache.lucene.analysis.icu.ICUNormalizer2Filter.incrementToken(ICUNormalizer2Filter.java:80)
        at org.apache.lucene.analysis.common@10.0.0-SNAPSHOT/org.apache.lucene.analysis.miscellaneous.ConditionalTokenFilter.incrementToken(ConditionalTokenFilter.java:203)
        at org.apache.lucene.test_framework@10.0.0-SNAPSHOT/org.apache.lucene.tests.analysis.ValidatingTokenFilter.incrementToken(ValidatingTokenFilter.java:81)
        at org.apache.lucene.test_framework@10.0.0-SNAPSHOT/org.apache.lucene.tests.analysis.BaseTokenStreamTestCase.checkResetException(BaseTokenStreamTestCase.java:926)
        at org.apache.lucene.test_framework@10.0.0-SNAPSHOT/org.apache.lucene.tests.analysis.BaseTokenStreamTestCase.checkRandomData(BaseTokenStreamTestCase.java:1068)
        at org.apache.lucene.analysis.tests@10.0.0-SNAPSHOT/org.apache.lucene.analysis.tests.TestRandomChains.testRandomChainsWithLargeStrings(TestRandomChains.java:978)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

@rmuir
Copy link
Member

rmuir commented Feb 14, 2024

good catch! should we move this check to setTokenType()? Since it is a public method, it seems like a better place to add the check?

@uschindler
Copy link
Contributor

I wonder why the token stream has a setter at all. The field should be final.

I thought we want to have those settings all final and only set on construction.

@easyice
Copy link
Contributor Author

easyice commented Feb 15, 2024

Thank you for the great suggestions!

@uschindler You are right, all the setters are used after the construction only, It makes sense if they are only set on construction. The only thing to consider is the impact of API changes to the users. for the time being I follow the @rmuir 's suggestion, move this check to setTokenType.

@uschindler
Copy link
Contributor

Let's open another issue about this. I think we did the final only fields for query instances, but token streams are not behaving bad as they are not cached and have state.

But we should avoid that in future. There is no good reason to change config of token streams after construction.

@uschindler uschindler self-assigned this Feb 15, 2024
@uschindler uschindler added this to the 9.11.0 milestone Feb 15, 2024
@uschindler uschindler merged commit b16d711 into apache:main Feb 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants