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

Paul Elschot commented on LUCENE-7277:
--------------------------------------

The rationale is that this code is common to some subclasses of Query, see also 
the patch at LUCENE-6372.

There is nothing specific in this code for the Query class, any abstract class 
without attributes might have these definitions.
Is there a way to enforce overriding a non abstract method in a subclass?

Aside: somehow this reminds me of the TermQuery constructors, see LUCENE-6821 
and LUCENE-4483.
It's probably better to be on the safe side here too, and make these methods 
abstract.

Otherwise we could add a remark in the javadocs of these methods that these 
methods should normally be overridden and called via super.

A reminder in the javadocs of IndexSearcher would also help.



> Make Query.hashCode and Query.equals abstract
> ---------------------------------------------
>
>                 Key: LUCENE-7277
>                 URL: https://issues.apache.org/jira/browse/LUCENE-7277
>             Project: Lucene - Core
>          Issue Type: Improvement
>            Reporter: Dawid Weiss
>            Assignee: Dawid Weiss
>            Priority: Trivial
>
> Custom subclasses of the Query class have the default implementation of 
> hashCode/equals that make all instances of the subclass equal. If somebody 
> doesn't know this it can be pretty tricky to debug with IndexSearcher's query 
> cache on. 
> Is there any rationale for declaring it this way instead of making those 
> methods abstract (and enforcing their proper implementation in a subclass)?
> {code}
>   public int hashCode() {
>     return getClass().hashCode();
>   }
>   public boolean equals(Object obj) {
>     if (obj == null)
>       return false;
>     return getClass() == obj.getClass();
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to