try with resource when reading symbol cache data to avoid leaking file handles

This commit is contained in:
Martin Lippert
2019-08-07 16:47:48 +02:00
parent 2768a29f09
commit 379f3c102a

View File

@@ -99,11 +99,12 @@ public class SymbolCacheOnDisc implements SymbolCache {
@Override
public Pair<CachedSymbol[], Multimap<String, String>> retrieve(SymbolCacheKey cacheKey, String[] files) {
try {
File cacheStore = new File(cacheDirectory, cacheKey.toString() + ".json");
if (cacheStore.exists()) {
Gson gson = createGson();
JsonReader reader = new JsonReader(new FileReader(cacheStore));
File cacheStore = new File(cacheDirectory, cacheKey.toString() + ".json");
if (cacheStore.exists()) {
Gson gson = createGson();
try (JsonReader reader = new JsonReader(new FileReader(cacheStore))) {
CacheStore store = gson.fromJson(reader, CacheStore.class);
SortedMap<String, Long> timestampedFiles = Arrays.stream(files)
@@ -133,9 +134,9 @@ public class SymbolCacheOnDisc implements SymbolCache {
);
}
}
}
catch (Exception e) {
log.error("error reading cached symbols", e);
catch (Exception e) {
log.error("error reading cached symbols", e);
}
}
return null;
}