[
https://issues.apache.org/jira/browse/LUCENE-9744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17280950#comment-17280950
]
Alan Woodward commented on LUCENE-9744:
---------------------------------------
> There is no time pressure on this at all, Alan
I found a fix already though :). This is in fact due to the degeneracy; in a
'normal' min-should-match scenario, the leading interval gets moved on once a
match is found to see if the interval can be minimized, in the same way that an
unordered interval does. In order to return the correct sub-matches, we cache
this leading interval before it is moved on. Then when getSubMatches is
called, we collect the cached lead interval and then all the other intervals
that are behind the end of the current interval, which will filter out the
*current* position of the lead. In the degenerate case, though, the interval
is already minimized (because it only has one sub-interval), and so the lead
variable never gets set. And so when we collect sub matches, collecting the
lead returns null.
I'm attaching a patch with a) a test for this case, and b) a fix in the factory
method that ensures we don't ever actually get a degenerate min-should-match
interval.
PS I see that your test uses the matches highlighter, this was helpful for
finding the bug but of course couldn't be backported along with a fix because
the matches highlighter still isn't in 8.x, hint hint :)
> NPE on a degenerate query in
> MinimumShouldMatchIntervalsSource$MinimumMatchesIterator.getSubMatches()
> -----------------------------------------------------------------------------------------------------
>
> Key: LUCENE-9744
> URL: https://issues.apache.org/jira/browse/LUCENE-9744
> Project: Lucene - Core
> Issue Type: Bug
> Affects Versions: master (9.0), 8.7
> Reporter: Dawid Weiss
> Priority: Major
> Attachments: LUCENE-9744.patch
>
>
> This query:
> {code}
> Query q1 =
> new IntervalQuery(
> FLD_TEXT1,
> Intervals.ordered(
> Intervals.atLeast(1, Intervals.term("foo")),
> Intervals.atLeast(1, Intervals.term("bar"))));
> {code}
> produces an NPE when retrieving match regions. Note degenerate atLeast with
> only one argument - this may play a role but it's not signaled anywhere
> before (the query itself does select the right documents, NPE blows up when
> matches are retrieved).
> Stack:
> {code}
> java.lang.NullPointerException
> at
> __randomizedtesting.SeedInfo.seed([2DDAAECF04D90D2F:EB69410397F8761E]:0)
> at
> org.apache.lucene.queries.intervals.MinimumShouldMatchIntervalsSource$MinimumMatchesIterator.getSubMatches(MinimumShouldMatchIntervalsSource.java:389)
> at
> org.apache.lucene.queries.intervals.CachingMatchesIterator.cache(CachingMatchesIterator.java:39)
> at
> org.apache.lucene.queries.intervals.CachingMatchesIterator.next(CachingMatchesIterator.java:68)
> at
> org.apache.lucene.queries.intervals.IntervalMatches$2.nextInterval(IntervalMatches.java:137)
> at
> org.apache.lucene.queries.intervals.OrderedIntervalsSource$OrderedIntervalIterator.nextInterval(OrderedIntervalsSource.java:166)
> at
> org.apache.lucene.queries.intervals.ConjunctionIntervalsSource.matches(ConjunctionIntervalsSource.java:89)
> at
> org.apache.lucene.queries.intervals.IntervalQuery$IntervalWeight.lambda$matches$0(IntervalQuery.java:177)
> at org.apache.lucene.search.MatchesUtils.forField(MatchesUtils.java:115)
> at
> org.apache.lucene.queries.intervals.IntervalQuery$IntervalWeight.matches(IntervalQuery.java:174)
> at
> org.apache.lucene.search.matchhighlight.MatchRegionRetriever.highlightDocument(MatchRegionRetriever.java:210)
> at
> org.apache.lucene.search.matchhighlight.MatchRegionRetriever.highlightDocuments(MatchRegionRetriever.java:193)
> at
> org.apache.lucene.search.matchhighlight.MatchRegionRetriever.highlightDocuments(MatchRegionRetriever.java:146)
> at
> org.apache.lucene.search.matchhighlight.MatchHighlighter.highlight(MatchHighlighter.java:236)
> at
> org.apache.lucene.search.matchhighlight.TestMatchHighlighter.lambda$testNpeOnIntervalQuery$7(TestMatchHighlighter.java:540)
> at
> org.apache.lucene.search.matchhighlight.IndexBuilder.build(IndexBuilder.java:100)
> at
> org.apache.lucene.search.matchhighlight.TestMatchHighlighter.testNpeOnIntervalQuery(TestMatchHighlighter.java:510)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base/java.lang.reflect.Method.invoke(Method.java:564)
> {code}
> Repro test attached.
> [~romseygeek], help! :)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]