-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asMap() does not conform to the Map contract #174
Comments
Thanks, @ben-manes for putting this together. Great stuff. Getting the map implemented correctly for every detail is quite time consuming, so I did cut a few corners. With the test suite it should be possible to get it right quite quickly. |
Just made the necessary changes. Unfortunately the Map contract for
The pseudo code aligned to the contract specified on the
In the last commit I changed the semantics of
So probably I better keep the semantics on |
This is a confusion for null-valued maps, causing a recent bug in TreeMap (JDK-8259622) (you might want to add that test case). I suppose |
Looking further into it, problem is, when changing I think there are not so many users that actually do enable In the long run we could rename the methods, e.g. from |
Fixed and released as bug fix, see https://github.com/cache2k/cache2k/releases/tag/v2.2.1.Final |
I've been using Guava's conformance tests since Caffeine's inception as a secondary guard in addition to my own suite. I recently extended it to run across more cache configurations, similar to how the core suite runs a test scenario against every configuration that matches its specification constraint. The intent is to ensure that a particular feature does not interact poorly and break the expected behavior. That's a brute force approach, e.g. that change expanded the suite by ~350,000 cases.
I did a quick check to see if other caches passed the suite, and unfortunately I found issues here (83 failures, 13 errors). That's not surprising, e.g. another library had failures too (jhalterman/expiringmap#48).
In this library a few examples are,
computeIfAbsent
that returns null indicates that the mapping should not be established. Instead this is treated as a null value, causing either an error or to be cached based on the builder configuration.equals(map)
should be symmetric and therefore two maps with the same mappings will be equal to one another. This is violated wherecache.asMap().equals(other)
fails if other does not implementConcurrentMapWrapper
, whereasother.equals(cache.asMap())
will pass. SimilarlyhashCode
violates the basic equality contract. While a documented break, it seems like an unnecessary violation.Map.Entry
not implementing equality so thatentrySet.containsAll(entrySet)
fails.If helpful, Caffeine's test runners are defined in CaffeineMapTests and MapTestFactory.
A simple runner for cache2k
The text was updated successfully, but these errors were encountered: