diff --git a/src/infinity/NearInfinity.java b/src/infinity/NearInfinity.java index a7c7efd9a..b5e65ab87 100644 --- a/src/infinity/NearInfinity.java +++ b/src/infinity/NearInfinity.java @@ -36,6 +36,7 @@ import infinity.updater.Updater; import infinity.util.IdsMapCache; import infinity.util.StringResource; +import infinity.util.Table2daCache; import infinity.util.io.FileLookup; import infinity.util.io.FileNI; @@ -757,6 +758,7 @@ private static void clearCache() { FileLookup.getInstance().clearCache(); IdsMapCache.clearCache(); + Table2daCache.clearCache(); SearchFrame.clearCache(); StringResource.close(); ProRef.clearCache(); diff --git a/src/infinity/util/IdsMapCache.java b/src/infinity/util/IdsMapCache.java index ea254abc7..5316b6671 100644 --- a/src/infinity/util/IdsMapCache.java +++ b/src/infinity/util/IdsMapCache.java @@ -17,7 +17,9 @@ public final class IdsMapCache public static void cacheInvalid(ResourceEntry entry) { - common.remove(entry.toString().toUpperCase(Locale.ENGLISH)); + if (entry != null) { + common.remove(entry.toString().toUpperCase(Locale.ENGLISH)); + } } public static void clearCache() @@ -25,21 +27,26 @@ public static void clearCache() common.clear(); } - public static synchronized IdsMap get(String name) // name must be in UPPER CASE + public static synchronized IdsMap get(String name) { - IdsMap map = common.get(name); - if (map == null) { - ResourceEntry resEntry = ResourceFactory.getResourceEntry(name); - if (resEntry == null && name.equalsIgnoreCase("ATTSTYLE.IDS")) - resEntry = ResourceFactory.getResourceEntry("ATTSTYL.IDS"); - if (resEntry == null) - System.err.println("Could not find " + name); - else { - map = new IdsMap(resEntry); - common.put(name, map); + IdsMap retVal = null; + if (name != null) { + name = name.trim().toUpperCase(Locale.ENGLISH); + retVal = common.get(name); + if (retVal == null) { + ResourceEntry resEntry = ResourceFactory.getResourceEntry(name); + if (resEntry == null && name.equals("ATTSTYLE.IDS")) { + resEntry = ResourceFactory.getResourceEntry("ATTSTYL.IDS"); + } + if (resEntry == null) { + System.err.println("Could not find " + name); + } else { + retVal = new IdsMap(resEntry); + common.put(name, retVal); + } } } - return map; + return retVal; } private IdsMapCache(){} diff --git a/src/infinity/util/Table2daCache.java b/src/infinity/util/Table2daCache.java index db34cfddb..54e2a2460 100644 --- a/src/infinity/util/Table2daCache.java +++ b/src/infinity/util/Table2daCache.java @@ -16,7 +16,9 @@ public class Table2daCache /** Removes the specified 2DA resource from the cache. */ public static synchronized void cacheInvalid(ResourceEntry entry) { - map.remove(entry); + if (entry != null) { + map.remove(entry); + } } /** Removes all cached 2DA resources. */