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 Mon, 16 May 2016 07:39:12 GMT


Dawid Weiss commented on LUCENE-7277:

While it may sound like a good idea to put some of the shared "equivalence checks" in the
superclass, it's actually the misleading part because, if left as-is and not overridden in
a subclass, it results in an incorrect behavior (the query object is cached for all instances
of the subclass).

If query hash/equals is so important (and it is), I'd make it an abstract method to enforce
proper override in all subclasses.

> 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