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

David Smiley commented on SOLR-14596:
-------------------------------------

bq. I don't think users should need to ask us to abide by standard Java 
"contracts". This is just part of being a well-behaved Java client library.

I disagree with that general notion very strongly.  A codebase shouldn't 
implementing hashCode on *all* classes.  Only where it is useful.  You didn't 
say "all" but I think your reasoning ultimately leads to "all" -- assuming we 
had infinite time to make the code as "well-behaved" as you say, as possible.  
There is no Java/API contract I'm aware of that says classes must implement 
hashCode -- i.e. specifically that's it's wrong to throw 
UnsupportedOperationException.  Arguably it was a mistake that Gosling had 
Object.hashCode() _not_ throw UnsupportedOperationException as the default 
implementation.  It's easy to forget and write code that puts objects into keys 
of maps or sets and have it not work as intended.

You refer to MockingHttp2SolrClient's Set<SolrRequest>, which may give evidence 
to my point, though I'm not sure.  If the author's intent was equivalent (i.e. 
not necessarily same instance) SolrRequests, then it's faulty and it's hard to 
know it's faulty without knowing if SolrRequest implements hashCode.  If the 
intent was only identical SolrRequest instances, then it's working as-designed. 
 CC [~caomanhdat] BTW this class appears completely unused.

bq. This is very low-complexity code - you can generate similar implementations 
with an IDE.

It's easy for code evolution (new fields) to leave equals/hashCode out of date, 
leading to very subtle bugs!

> Add equals()/hashCode() impls to SolrJ Request objects
> ------------------------------------------------------
>
>                 Key: SOLR-14596
>                 URL: https://issues.apache.org/jira/browse/SOLR-14596
>             Project: Solr
>          Issue Type: Improvement
>          Components: SolrJ
>    Affects Versions: master (9.0), 8.5.2
>            Reporter: Jason Gerlowski
>            Priority: Minor
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> Currently, many SolrRequest classes (e.g. UpdateRequest) don't implement 
> {{equals()}} or {{hashCode()}}
> This isn't a problem for Solr's normal operation, but it can be a barrier in 
> unit testing SolrJ client code.  {{equals()}} implementations would make it 
> much easier to assert that client code is building the request that 
> developers _think_ it's building.  Of course, this testing benefit would 
> apply to Solr's own tests which use SolrJ.
> This ticket covers making sure that the more popular SolrRequest objects have 
> equals/hashcode implementations useful for testers.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to