From 5c6cd57a4d9526e8c0c88fdac574256728c38096 Mon Sep 17 00:00:00 2001 From: riking Date: Fri, 30 Aug 2013 18:40:48 -0700 Subject: [PATCH] Use a MutableBoolean to synchronize on instead of a Boolean The code synchronizes on a boxed primitive constant, such as an Boolean. Since there normally exist only two Boolean objects, this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness and possible deadlock. This commit uses the MutableBoolean class from commons-lang, which is included in bukkit.jar. --- src/com/massivecraft/mcore/InternalListener.java | 2 +- src/com/massivecraft/mcore/util/SmokeUtil.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/com/massivecraft/mcore/InternalListener.java b/src/com/massivecraft/mcore/InternalListener.java index c15a00b6..f28ac6b2 100644 --- a/src/com/massivecraft/mcore/InternalListener.java +++ b/src/com/massivecraft/mcore/InternalListener.java @@ -154,7 +154,7 @@ public class InternalListener implements Listener if (cause != DamageCause.BLOCK_EXPLOSION) return; // ... and that explosion is a fake ... - if (SmokeUtil.fakeExplosion == false) return; + if (!SmokeUtil.fakeExplosion.booleanValue()) return; // ... then cancel the event and the damage. event.setCancelled(true); diff --git a/src/com/massivecraft/mcore/util/SmokeUtil.java b/src/com/massivecraft/mcore/util/SmokeUtil.java index b8a6886e..370519c0 100644 --- a/src/com/massivecraft/mcore/util/SmokeUtil.java +++ b/src/com/massivecraft/mcore/util/SmokeUtil.java @@ -3,6 +3,7 @@ package com.massivecraft.mcore.util; import java.util.Collection; import java.util.Random; +import org.apache.commons.lang.mutable.MutableBoolean; import org.bukkit.Effect; import org.bukkit.Location; @@ -89,14 +90,14 @@ public class SmokeUtil fakeExplosion(location, 4F); } - public static Boolean fakeExplosion = false; + public static MutableBoolean fakeExplosion = new MutableBoolean(false); public static void fakeExplosion(Location location, float power) { synchronized (fakeExplosion) { - fakeExplosion = true; + fakeExplosion.setValue(true); location.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), power, false, false); - fakeExplosion = false; + fakeExplosion.setValue(false); } }