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:
Tomas Slusny
2019-02-16 03:56:33 +01:00
parent a0cdd64719
commit e8019d0517
2 changed files with 12 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import net.runelite.cache.ConfigType;
@@ -233,6 +234,11 @@ public class CacheService
public List<ItemDefinition> getItems() throws IOException
{
CacheEntry cache = findMostRecent();
if (cache == null)
{
return Collections.emptyList();
}
IndexEntry indexEntry = findIndexForCache(cache, IndexType.CONFIGS.getNumber());
ArchiveEntry archiveEntry = findArchiveForIndex(indexEntry, ConfigType.ITEM.getId());
ArchiveFiles archiveFiles = getArchiveFiles(archiveEntry);

View File

@@ -489,10 +489,16 @@ public class ItemService
public void reloadItems() throws IOException
{
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()
.filter(item -> item.isTradeable)
.mapToInt(item -> item.id)
.toArray();
log.debug("Loaded {} tradeable items", tradeableItems.length);
}