Jay Gorrell (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=622a122...
) *created* an issue
Hibernate Validator (
https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiM2U0OTVmZTM3N...
) / Bug (
https://hibernate.atlassian.net/browse/HV-1946?atlOrigin=eyJpIjoiM2U0OTVm...
) HV-1946 (
https://hibernate.atlassian.net/browse/HV-1946?atlOrigin=eyJpIjoiM2U0OTVm...
) PathImpl.createCopy() only performs a shallow copy (
https://hibernate.atlassian.net/browse/HV-1946?atlOrigin=eyJpIjoiM2U0OTVm...
)
Issue Type: Bug Affects Versions: 6.0.23.Final Assignee: Unassigned Attachments:
JTextArrayValueExtractor.java, PathProblemTest.java Components: engine Created:
01/May/2023 17:55 PM Environment: JDK zulu8.68.0.21-ca-jdk8.0.362-win_x64
Hibernate validator versions: hibernate-validator-6.0.23.Final.jar,
hibernate-validator-6.2.5.Final.jar Priority: Major Reporter: Jay Gorrell (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=622a122...
)
hen calling Validator.validateValue() with a class containing an array field with a single
Pattern validation on the entire array which creates violations, the index in the path of
the validations is only correct for the last item in the array. The index for the
violations on other elements is always set to the index of the last element.
I spent some time debugging this and found the PathImpl.createCopy(), which calls the copy
constructor PathImpl(PathImpl path), is only doing a shallow copy of the values. The
validation for each element in the array is using the same instance of the nodeList
property in PathImpl instead of a different one for each validation. This happens because
the copy constructor does not create a new list, but uses the existing one. The code that
changes the currentLeafNode values is then update that list which ends up in each
violation path.
I believe the fix to be on line 351 of PathImpl in the 6.0.23.Final code would be to
replace that line with this one.:
nodeList = new ArrayList<path.nodeList>() // Need null check for path.nodeList?
(
https://hibernate.atlassian.net/browse/HV-1946#add-comment?atlOrigin=eyJp...
) Add Comment (
https://hibernate.atlassian.net/browse/HV-1946#add-comment?atlOrigin=eyJp...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100224- sha1:07bd2b7 )