Procházet zdrojové kódy

BETA: Fixing NPE in ItemsOnGroundManager related to non thread-safe list.
* Reported by: valdaron

Rumen Nikiforov před 12 roky
rodič
revize
e6660d2d77

+ 8 - 13
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/ItemsOnGroundManager.java

@@ -22,8 +22,6 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javolution.util.FastList;
-
 import com.l2jserver.Config;
 import com.l2jserver.L2DatabaseFactory;
 import com.l2jserver.gameserver.ItemsAutoDestroy;
@@ -31,6 +29,7 @@ import com.l2jserver.gameserver.ThreadPoolManager;
 import com.l2jserver.gameserver.model.L2World;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 import com.l2jserver.gameserver.model.items.type.L2EtcItemType;
+import com.l2jserver.util.L2FastList;
 
 /**
  * This class manage all items on ground.
@@ -41,15 +40,11 @@ public class ItemsOnGroundManager
 {
 	static final Logger _log = Logger.getLogger(ItemsOnGroundManager.class.getName());
 	
-	protected List<L2ItemInstance> _items = null;
+	protected List<L2ItemInstance> _items = new L2FastList<>(true);
 	private final StoreInDb _task = new StoreInDb();
 	
 	protected ItemsOnGroundManager()
 	{
-		if (Config.SAVE_DROPPED_ITEM)
-		{
-			_items = new FastList<>();
-		}
 		if (Config.SAVE_DROPPED_ITEM_INTERVAL > 0)
 		{
 			ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(_task, Config.SAVE_DROPPED_ITEM_INTERVAL, Config.SAVE_DROPPED_ITEM_INTERVAL);
@@ -57,11 +52,6 @@ public class ItemsOnGroundManager
 		load();
 	}
 	
-	public static final ItemsOnGroundManager getInstance()
-	{
-		return SingletonHolder._instance;
-	}
-	
 	private void load()
 	{
 		// If SaveDroppedItem is false, may want to delete all items previously stored to avoid add old items on reactivate
@@ -173,7 +163,7 @@ public class ItemsOnGroundManager
 	
 	public void removeObject(L2ItemInstance item)
 	{
-		if (Config.SAVE_DROPPED_ITEM && (_items != null))
+		if (Config.SAVE_DROPPED_ITEM)
 		{
 			_items.remove(item);
 		}
@@ -273,6 +263,11 @@ public class ItemsOnGroundManager
 		}
 	}
 	
+	public static final ItemsOnGroundManager getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
 	private static class SingletonHolder
 	{
 		protected static final ItemsOnGroundManager _instance = new ItemsOnGroundManager();