lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dawid Weiss (JIRA)" <>
Subject [jira] [Commented] (LUCENE-7277) Make Query.hashCode and Query.equals abstract
Date Sun, 15 May 2016 19:20:13 GMT


Dawid Weiss commented on LUCENE-7277:

I fail see how an equivalence relationship over all objects of a class could be useful for
caching reason (perhaps with the exception of MatchAllQuery)? I know for a fact it's misleading
because a seasoned developer made the mistake of not overriding it (assuming the defaults
are instance-equivalence, inherited from Object).

bq. Is there a way to enforce overriding a non abstract method in a subclass?

Yes, you redeclare an overriden method as an abstract one. Then all subclasses have to reimplement
it properly.

> Make Query.hashCode and Query.equals abstract
> ---------------------------------------------
>                 Key: LUCENE-7277
>                 URL:
>             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

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message