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.
This commit is contained in:
riking committed 2013-08-30 18:40:48 -07:00
1 parent f78872c157
commit 5c6cd57a4d
2 files changed
+5 -4

No files matched your search

@@ -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);
@@ -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);
}
}