Skip to content

BloomFilter multithread problem: put() NOT atomic #3055

Description

@davidecaroselli

Hello team!

I just found a problem using com.google.common.hash.BloomFilter with more than one thread. Long story short: put() is not atomic so I am able to reproduce a false negative.

This is the config in pom.xml:

<dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>24.0-jre</version>
</dependency>

I created a simple Test.java class that proves the point. The fix is also included in the file: just uncomment lines 56 and 58 (make put() synchronized).

Looking at the BloomFilter javadoc I see:

 * As of Guava 23.0, this class is thread-safe and lock-free. It internally uses atomics and
 * compare-and-swap to ensure correctness when multiple threads are used to access it.

So I suppose that I'm not doing anything "wrong". Can you please confirm the issue or tell me where I'm using the library wrong?

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions