mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Every error code setter in SQLErrorCodes sorts its array with StringUtils.sortStringArray, and CustomSQLErrorCodesTranslation does the same, because SQLErrorCodeSQLExceptionTranslator looks the codes up with Arrays.binarySearch. setDuplicateKeyCodes was the only setter that stored the supplied array as-is. With an unsorted list of duplicate key codes, the binary search finds or misses a code depending on where the values happen to sit: for codes it misses, the translator silently falls through to the SQLState fallback and reports a DataIntegrityViolationException, or fails to translate at all, instead of the configured DuplicateKeyException. The default sql-error-codes.xml is not affected since its lists are already sorted; the mismatch surfaces for custom configurations, for example codes of different digit lengths listed in numeric order. setDuplicateKeyCodes now sorts the array like all sibling setters. The new test covers an unsorted custom list whose codes previously hit or missed depending on their position. Closes gh-37235 Signed-off-by: junhyeong9812 <pickjog@gmail.com>