[ https://issues.apache.org/jira/browse/LUCENE-10431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17497915#comment-17497915 ]
Michael Bien commented on LUCENE-10431: --------------------------------------- thanks for the tips. I might have found the cause. The BooleanQuery in question is constructed as follows: {code:java} add g:org?eclipse?jetty (groupId:org?eclipse?jetty*) with SHOULD add a:org?eclipse?jetty (artifactId:org?eclipse?jetty*) with SHOULD add v:org.eclipse.jetty* with SHOULD add n:org.eclipse.jetty* with SHOULD add d:org.eclipse.jetty* with SHOULD add +classnames:org +classnames:eclipse +classnames:jetty with SHOULD build: org.apache.lucene.search.BooleanQuery$Builder@4c2e43fc result: (g:org?eclipse?jetty (groupId:org?eclipse?jetty*)) (a:org?eclipse?jetty (artifactId:org?eclipse?jetty*)) v:org.eclipse.jetty* n:org.eclipse.jetty* d:org.eclipse.jetty* (+classnames:org +classnames:eclipse +classnames:jetty){code} (user searching "org.eclipse.jetty" in the maven repository index) However, *before* each query is added to the builder. The rewrite method is changed to "CONSTANT_SCORE_BOOLEAN_REWRITE" recursively (builder.add(setBooleanRewrite(q), occur)). {code:java} private static Query setBooleanRewrite (final Query q) { if (q instanceof MultiTermQuery) { ((MultiTermQuery)q).setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE); } else if (q instanceof BooleanQuery) { for (BooleanClause c : ((BooleanQuery)q).clauses()) { setBooleanRewrite(c.getQuery()); } } return q; }{code} If I remove this, I don't see any assertion errors. Is this not a legal way of changing the rewrite method? I am a little bit worried that this is only hiding the issue and it might appear somewhere else. (btw using the two arg add didn't help, but I am going to change it anyway since its shorter :)) > AssertionError in BooleanQuery.hashCode() > ----------------------------------------- > > Key: LUCENE-10431 > URL: https://issues.apache.org/jira/browse/LUCENE-10431 > Project: Lucene - Core > Issue Type: Bug > Affects Versions: 8.11.1 > Reporter: Michael Bien > Priority: Major > > Hello devs, > the constructor of BooleanQuery can under some circumstances trigger a hash > code computation before "clauseSets" is fully filled. Since BooleanClause is > using its query field for the hash code too, it can happen that the "wrong" > hash code is stored, since adding the clause to the set triggers its > hashCode(). > If assertions are enabled the check in BooleanQuery, which recomputes the > hash code, will notice it and throw an error. > exception: > {code:java} > java.lang.AssertionError > at org.apache.lucene.search.BooleanQuery.hashCode(BooleanQuery.java:614) > at java.base/java.util.Objects.hashCode(Objects.java:103) > at java.base/java.util.HashMap$Node.hashCode(HashMap.java:298) > at java.base/java.util.AbstractMap.hashCode(AbstractMap.java:527) > at org.apache.lucene.search.Multiset.hashCode(Multiset.java:119) > at java.base/java.util.EnumMap.entryHashCode(EnumMap.java:717) > at java.base/java.util.EnumMap.hashCode(EnumMap.java:709) > at java.base/java.util.Arrays.hashCode(Arrays.java:4498) > at java.base/java.util.Objects.hash(Objects.java:133) > at > org.apache.lucene.search.BooleanQuery.computeHashCode(BooleanQuery.java:597) > at org.apache.lucene.search.BooleanQuery.hashCode(BooleanQuery.java:611) > at java.base/java.util.HashMap.hash(HashMap.java:340) > at java.base/java.util.HashMap.put(HashMap.java:612) > at org.apache.lucene.search.Multiset.add(Multiset.java:82) > at org.apache.lucene.search.BooleanQuery.<init>(BooleanQuery.java:154) > at org.apache.lucene.search.BooleanQuery.<init>(BooleanQuery.java:42) > at > org.apache.lucene.search.BooleanQuery$Builder.build(BooleanQuery.java:133) > {code} > I noticed this while trying to upgrade the NetBeans maven indexer modules > from lucene 5.x to 8.x https://github.com/apache/netbeans/pull/3558 -- 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