Skip to content

Potential race condition in listener adding code #2755

Closed
@o-l-o

Description

@o-l-o

I'm pretty sure that there is potential race condition in the following code:

               Set<Topic> set = listenerTopics.get(listener);

		if (set == null) {
			set = new CopyOnWriteArraySet<>();
			listenerTopics.put(listener, set);
		}

The solution could be to replace it with something like this:

Set<Topic> set = listenerTopics.computeIfAbsent(listener, $ -> new CopyOnWriteArraySet<>());

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions