Lucene - Core
  1. Lucene - Core
  2. LUCENE-6333

Clean up overridden .equals and .hashCode methods in Query subclasses

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 5.1, 6.0
    • Component/s: core/search
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      As a followup to LUCENE-6304, all classes that subclass Query and override the equals and hashCode methods should call super.equals/hashCode and, when possible, not override the methods at all.

      For example, TermQuery.hashCode overrides the Query.hashCode, but will be exactly the same code once LUCENE-6304 is merged.

      1. LUCENE-6333.patch
        14 kB
        Lee Hinman
      2. LUCENE-6333-2.patch
        2 kB
        Lee Hinman
      3. LUCENE-6333-2.patch
        2 kB
        Lee Hinman

        Activity

        Hide
        Lee Hinman added a comment -

        Here's a patch that cleans up the hashCode and equals methods for most queries.

        I removed the extra getBoost comparison because the Query superclass does that comparison. I was also able to remove some overridden methods that only did exactly what the Query implementation does.

        Show
        Lee Hinman added a comment - Here's a patch that cleans up the hashCode and equals methods for most queries. I removed the extra getBoost comparison because the Query superclass does that comparison. I was also able to remove some overridden methods that only did exactly what the Query implementation does.
        Hide
        Adrien Grand added a comment -

        Thanks Lee, the patch looks good to me. I'll commit it later today if there are no objections.

        Show
        Adrien Grand added a comment - Thanks Lee, the patch looks good to me. I'll commit it later today if there are no objections.
        Hide
        ASF subversion and git services added a comment -

        Commit 1664384 from Adrien Grand in branch 'dev/trunk'
        [ https://svn.apache.org/r1664384 ]

        LUCENE-6333: Clean up overridden .equals and .hashCode methods in Query subclasses.

        Show
        ASF subversion and git services added a comment - Commit 1664384 from Adrien Grand in branch 'dev/trunk' [ https://svn.apache.org/r1664384 ] LUCENE-6333 : Clean up overridden .equals and .hashCode methods in Query subclasses.
        Hide
        Adrien Grand added a comment -

        Thanks Lee!

        Show
        Adrien Grand added a comment - Thanks Lee!
        Hide
        ASF subversion and git services added a comment -

        Commit 1664412 from Adrien Grand in branch 'dev/branches/branch_5x'
        [ https://svn.apache.org/r1664412 ]

        LUCENE-6333: Clean up overridden .equals and .hashCode methods in Query subclasses.

        Show
        ASF subversion and git services added a comment - Commit 1664412 from Adrien Grand in branch 'dev/branches/branch_5x' [ https://svn.apache.org/r1664412 ] LUCENE-6333 : Clean up overridden .equals and .hashCode methods in Query subclasses.
        Hide
        Robert Muir added a comment -

        Lets go thru this patch again. I encountered some bugs.

        For example, all TermsQuerys currently return the same hashcode.

        Show
        Robert Muir added a comment - Lets go thru this patch again. I encountered some bugs. For example, all TermsQuerys currently return the same hashcode.
        Hide
        Robert Muir added a comment -

        I went thru the patch and i don't see any other issues with it. I think the only problem is TermsQuery?

        Show
        Robert Muir added a comment - I went thru the patch and i don't see any other issues with it. I think the only problem is TermsQuery?
        Hide
        Lee Hinman added a comment -

        Here is an additional patch (now that the previous LUCENE-6333.patch was applied) that adds a correct hashCode method for TermsQuery as well as tests that catch this if it happens in the future.

        Show
        Lee Hinman added a comment - Here is an additional patch (now that the previous LUCENE-6333 .patch was applied) that adds a correct hashCode method for TermsQuery as well as tests that catch this if it happens in the future.
        Hide
        Robert Muir added a comment -

        Thanks for the fix.

        I think the test may fail sporatically, if the randomly generated terms happen to cause a hash collision. Maybe the test can just use some hardcoded terms like "apple" and "orange", which will still find the bug.

        Show
        Robert Muir added a comment - Thanks for the fix. I think the test may fail sporatically, if the randomly generated terms happen to cause a hash collision. Maybe the test can just use some hardcoded terms like "apple" and "orange", which will still find the bug.
        Hide
        Lee Hinman added a comment -

        I think the test may fail sporatically, if the randomly generated terms happen to cause a hash collision. Maybe the test can just use some hardcoded terms like "apple" and "orange", which will still find the bug.

        I agree, here's a new patch that uses "apple" and "orange" as you recommended.

        Show
        Lee Hinman added a comment - I think the test may fail sporatically, if the randomly generated terms happen to cause a hash collision. Maybe the test can just use some hardcoded terms like "apple" and "orange", which will still find the bug. I agree, here's a new patch that uses "apple" and "orange" as you recommended.
        Hide
        ASF subversion and git services added a comment -

        Commit 1666528 from Robert Muir in branch 'dev/trunk'
        [ https://svn.apache.org/r1666528 ]

        LUCENE-6333: fix hashcode impl for TermsQuery

        Show
        ASF subversion and git services added a comment - Commit 1666528 from Robert Muir in branch 'dev/trunk' [ https://svn.apache.org/r1666528 ] LUCENE-6333 : fix hashcode impl for TermsQuery
        Hide
        ASF subversion and git services added a comment -

        Commit 1666530 from Robert Muir in branch 'dev/branches/branch_5x'
        [ https://svn.apache.org/r1666530 ]

        LUCENE-6333: fix hashcode impl for TermsQuery

        Show
        ASF subversion and git services added a comment - Commit 1666530 from Robert Muir in branch 'dev/branches/branch_5x' [ https://svn.apache.org/r1666530 ] LUCENE-6333 : fix hashcode impl for TermsQuery
        Hide
        Robert Muir added a comment -

        Thanks Lee!

        Show
        Robert Muir added a comment - Thanks Lee!
        Hide
        Timothy Potter added a comment -

        Bulk close after 5.1 release

        Show
        Timothy Potter added a comment - Bulk close after 5.1 release

          People

          • Assignee:
            Unassigned
            Reporter:
            Lee Hinman
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development