Ensure custom KProperty include the name in the hashcode by rozza · Pull Request #1710 · mongodb/mongo-java-driver

@rozza

The `pathCache` utilised the string representation of the KProperty instance.
The custom implementations didn't include the calculated path value, this can
lead to naming collisions in the pathCache key.

This commit adds `hashCode` and `equals` methods to ensure the `name` value is included
in our custom implementations of `KProperty1`. Finally, the cache key is explicitly
created using the same default `Any.toString()` implementation to ensure that all
implementations of `KProperty1` use the same logic to create the cacheKey.

JAVA-5868

nhachicha

@rozza

@rozza

nhachicha

@rozza rozza deleted the JAVA-5868 branch

May 19, 2025 09:01

vbabanin pushed a commit to vbabanin/mongo-java-driver that referenced this pull request

Jun 6, 2025
The `pathCache` utilised the string representation of the KProperty instance.
The custom implementations didn't include the calculated `path` value, this can
lead to naming collisions in the `pathCache` key.

This commit adds `hashCode` and `equals` methods to ensure the `name` value is included
in our custom implementations of `KProperty1`. Finally, the cache key now uses the `hashCode`
for the cacheKey.

JAVA-5868

(cherry picked from commit 172327b)