UnsupportedOperationException à java.util.AbstractList.ajouter

Je vais avoir des problèmes à obtenir un bloc de code à exécuter correctement. Je ne suis pas entièrement sûr de CE que ce code n' (je vais essayer d'obtenir un plugin qui est hors de date pour fonctionner correctement avec notre serveur), je sais juste que toutes les 20 minutes, il s'exécute et jette une erreur. Voici la section de code où le problème se pose:

public class DynamicThread extends Thread {
private LocalShops plugin = null;
public DynamicThread(ThreadGroup tgroup, String tname, LocalShops plugin) {
super(tgroup, tname);
this.plugin = plugin;
}
public void run() {
Map<ItemInfo, List<Integer>> itemStockMap = Collections.synchronizedMap(new HashMap<ItemInfo, List<Integer>>());
//Dump all the shop stock data into the map.
for ( Shop shop : plugin.getShopManager().getAllShops() ) {
for ( InventoryItem item : shop.getItems() ) {
if (itemStockMap.containsKey(item.getInfo()))
itemStockMap.get(item.getInfo()).add(item.getStock()); //Where error happens
else
itemStockMap.put(item.getInfo(), Arrays.asList(item.getStock()));     
}
}
for(ItemInfo item : itemStockMap.keySet()) {
List<Integer> stockList = GenericFunctions.limitOutliers(itemStockMap.get(item));
//remove the map before re-adding it
if (DynamicManager.getPriceAdjMap().containsKey(item)) 
DynamicManager.getPriceAdjMap().remove(item);
//Get the overall stock change for a given item and then calculate the adjustment given the volatility
int deltaStock = GenericFunctions.getSum(stockList) - Config.getGlobalBaseStock();
DynamicManager.getPriceAdjMap().put(item, GenericFunctions.getAdjustment(Config.getGlobalVolatility(), deltaStock)); 
}
Bukkit.getServer().getScheduler().callSyncMethod(plugin, plugin.getShopManager().updateSigns());
}

}

L'erreur se produit à partir de la ligne 42, qui est:

                itemStockMap.get(item.getInfo()).add(item.getStock());

L'erreur, il les sorties qui se passe toutes les 20 minutes deux fois avec 2 secondes entre les deux.

2012-02-16 16:53:25 [INFO] Launch Dynamic Thread
2012-02-16 16:53:25 [SEVERE] Exception in thread "dynamic" 
2012-02-16 16:53:25 [SEVERE] java.lang.UnsupportedOperationException
2012-02-16 16:53:25 [SEVERE] at java.util.AbstractList.add(AbstractList.java:131)
2012-02-16 16:53:25 [SEVERE] at java.util.AbstractList.add(AbstractList.java:91)
2012-02-16 16:53:25 [SEVERE] at       com.milkbukkit.localshops.threads.DynamicThread.run(DynamicThread.java:42)
2012-02-16 16:53:27 [INFO] Launch Dynamic Thread
2012-02-16 16:53:27 [SEVERE] Exception in thread "dynamic" 
2012-02-16 16:53:27 [SEVERE] java.lang.UnsupportedOperationException
2012-02-16 16:53:27 [SEVERE] at java.util.AbstractList.add(AbstractList.java:131)
2012-02-16 16:53:27 [SEVERE] at java.util.AbstractList.add(AbstractList.java:91)
2012-02-16 16:53:27 [SEVERE] at     com.milkbukkit.localshops.threads.DynamicThread.run(DynamicThread.java:42)

Merci d'avance pour toute aide.

  • Avez-vous remplacé equals et hashcode sur ItemInfo objet, parce que vous faites un containsKey appel sur la table de hachage. (itemStockMap.containsKey(item.getInfo()))
InformationsquelleAutor Erickj92 | 2012-02-16