Null-check cache when getting items in http service
It is not very useful exception and cache entry is null-checked everywhere else. Replace the exception with simple warning in logs. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -41,6 +41,7 @@ import java.io.InputStream;
|
|||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.cache.ConfigType;
|
import net.runelite.cache.ConfigType;
|
||||||
@@ -233,6 +234,11 @@ public class CacheService
|
|||||||
public List<ItemDefinition> getItems() throws IOException
|
public List<ItemDefinition> getItems() throws IOException
|
||||||
{
|
{
|
||||||
CacheEntry cache = findMostRecent();
|
CacheEntry cache = findMostRecent();
|
||||||
|
if (cache == null)
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
IndexEntry indexEntry = findIndexForCache(cache, IndexType.CONFIGS.getNumber());
|
IndexEntry indexEntry = findIndexForCache(cache, IndexType.CONFIGS.getNumber());
|
||||||
ArchiveEntry archiveEntry = findArchiveForIndex(indexEntry, ConfigType.ITEM.getId());
|
ArchiveEntry archiveEntry = findArchiveForIndex(indexEntry, ConfigType.ITEM.getId());
|
||||||
ArchiveFiles archiveFiles = getArchiveFiles(archiveEntry);
|
ArchiveFiles archiveFiles = getArchiveFiles(archiveEntry);
|
||||||
|
|||||||
@@ -489,10 +489,16 @@ public class ItemService
|
|||||||
public void reloadItems() throws IOException
|
public void reloadItems() throws IOException
|
||||||
{
|
{
|
||||||
List<ItemDefinition> items = cacheService.getItems();
|
List<ItemDefinition> items = cacheService.getItems();
|
||||||
|
if (items.isEmpty())
|
||||||
|
{
|
||||||
|
log.warn("Failed to load any items from cache, item price updating will be disabled");
|
||||||
|
}
|
||||||
|
|
||||||
tradeableItems = items.stream()
|
tradeableItems = items.stream()
|
||||||
.filter(item -> item.isTradeable)
|
.filter(item -> item.isTradeable)
|
||||||
.mapToInt(item -> item.id)
|
.mapToInt(item -> item.id)
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
log.debug("Loaded {} tradeable items", tradeableItems.length);
|
log.debug("Loaded {} tradeable items", tradeableItems.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user