Skip to content
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

putIfAbsent returns wrong value #26

Closed
GenghisChen opened this issue Sep 2, 2015 · 2 comments
Closed

putIfAbsent returns wrong value #26

GenghisChen opened this issue Sep 2, 2015 · 2 comments

Comments

@GenghisChen
Copy link

Using the cache in its ConcurrentMap form (.asMap()), when time-limited entries expire the .get() method returns null as is should, but the .putIfAbsent() method return the old-expired value.

Consider the following example:

    Cache<Integer, String> cache1 = Caffeine.newBuilder()
            .expireAfterWrite(1, TimeUnit.SECONDS)
            .build();
    ConcurrentMap<Integer, String> cache2 = cache1.asMap();

    cache2.put(1, "A");
    Thread.sleep(2000);
    System.out.println(cache2.get(1));  // Expect to see null (and see null)
    System.out.println(cache2.putIfAbsent(1, "B")); // Expect to see null (and see "A")
@ben-manes
Copy link
Owner

You're right! A million unit test executions and somehow I missed checking for this.

Thanks for the test case. I'll fix and release an update this evening.

@ben-manes
Copy link
Owner

Released v1.3.2 to Maven Central.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants