Copying PathImpl results in hashCode==0

Description

Function PathImpl.createCopy(PathImpl path) creates new PathImpl that has hashCode==0. This value is fixed and never changes (due to the algorithm in hascode() funcion). The correct value after copying should have been -1 or the same value as in the source object.

The problematic PathImpl with the zero hashCode is unfortunately returned from the validate() function:

Test:

Environment

None

Activity

Show:
Gunnar Morling
October 28, 2015, 3:25 PM

Hey , agreed, the hash code should be the same as the one of the copied node. Out of interest, is this a theoretical issue for you, or did you run into any problems in practice caused by that? Also, would you be interested in preparing a fix for this and sending a pull request for it?

Jiri Bilek
October 29, 2015, 9:31 AM

Hi Gunnar, unfortunately we really found this bug during development of our app. We used Paths as keys to a HashMap and then weren't able to find them because cloned Path had the buggy hashCode.
The fix is easy, I will prepare it and try to send a first pull request in my life
Jiri

Jiri Bilek
October 31, 2015, 4:38 PM
Edited

Added a pull request that fixes the issue.
https://github.com/hibernate/hibernate-validator/pull/444

Gunnar Morling
November 2, 2015, 7:20 AM

Thanks, ! Going to look at the PR asap; Could you check out and sign the JBoss CLA (contributor license agreement) in between? That's required for incorporating your change. Thanks again!

Jiri Bilek
November 2, 2015, 8:47 AM

CLA signed. Thanks.

Assignee

Unassigned

Reporter

Jiri Bilek

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

Priority

Minor
Configure