From 9170e48992b592a61c992623347e77377cf7d4eb Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Tue, 20 Nov 2012 03:32:44 +0100 Subject: [PATCH] Correct the concurrent initialization pattern. --- .../comphenix/protocol/async/PlayerSendingHandler.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/PlayerSendingHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/PlayerSendingHandler.java index 2854814a..cb234d88 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/PlayerSendingHandler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/PlayerSendingHandler.java @@ -99,10 +99,14 @@ class PlayerSendingHandler { // Safe concurrent initialization if (queues == null && createNew) { - QueueContainer previous = playerSendingQueues.putIfAbsent(name, new QueueContainer()); + final QueueContainer newContainer = new QueueContainer(); + + // Attempt to map the queue + queues = playerSendingQueues.putIfAbsent(name, newContainer); - if (previous != null) - queues = previous; + if (queues == null) { + queues = newContainer; + } } // Check for NULL again