-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Changed behavior of returned empty maps from LocalAsyncCache #864
Comments
oh, good catch. I knew of that annoying difference, but forgot at the time. I'll restore this and add unit tests to assert the null lookup behavior. |
…864) While a null lookup is not allowed for cache the operations (e.g. asMap.get), if an operation returned a map then this might not be consistant. Originally all of these cases used Collections' emptyMap() or unmodifiableMap(m), but a few cases switched to Map's of() or copyOf() alternatives. The former allows for null queries whereas the latter does not, and this could vary depending on if the result was populated. For consistency and retaining the original behavior, this is restored to the Collections' methods.
…864) While a null lookup is not allowed for cache the operations (e.g. asMap.get), if an operation returned a map then this might not be consistant. Originally all of these cases used Collections' emptyMap() or unmodifiableMap(m), but a few cases switched to Map's of() or copyOf() alternatives. The former allows for null queries whereas the latter does not, and this could vary depending on if the result was populated. For consistency and retaining the original behavior, this is restored to the Collections' methods.
|
Sorry, commented on the wrong issue! |
Released in 3.1.3 |
The change of LocalAsyncCache#composeResult, which swaps
Collections.emptyMap()
forMap.of()
has resulted in changed behavior of the returned maps.Collections.emptyMap()
does allow looking upnull
keys (resulting innull
values), whileMap.of()
returns JavasMapN
, which throws an exception whennull
is looked up (source below):This means that the following code fails with an exception when using Caffeine 3.1.2, instead of getting
null
from the map.Even though
Map#get
does not guarantee thatnull
keys can be used, Caffeine does not allow looking upnull
keys, andLoadingCache#getAll
explicitly states that the returned map "will never contain null keys or values", it is still a small but subtle change in behavior, which can cause runtime problems for users. Especially because it only occurs in the combination of a cache lookup of an emptyIterable
, and a lookup of anull
key in the returnedMap
.The text was updated successfully, but these errors were encountered: