Fix #592
This commit is contained in:
@@ -263,7 +263,7 @@ public class CacheRepository {
|
|||||||
try (RandomAccessFile file = new RandomAccessFile(indexFile.toFile(), "rw"); FileChannel channel = file.getChannel()) {
|
try (RandomAccessFile file = new RandomAccessFile(indexFile.toFile(), "rw"); FileChannel channel = file.getChannel()) {
|
||||||
FileLock lock = channel.lock();
|
FileLock lock = channel.lock();
|
||||||
try {
|
try {
|
||||||
ETagIndex indexOnDisk = JsonUtils.GSON.fromJson(new String(IOUtils.readFullyWithoutClosing(Channels.newInputStream(channel)), UTF_8), ETagIndex.class);
|
ETagIndex indexOnDisk = JsonUtils.fromMaybeMalformedJson(new String(IOUtils.readFullyWithoutClosing(Channels.newInputStream(channel)), UTF_8), ETagIndex.class);
|
||||||
Map<String, ETagItem> newIndex = joinETagIndexes(indexOnDisk == null ? null : indexOnDisk.eTag, index.values());
|
Map<String, ETagItem> newIndex = joinETagIndexes(indexOnDisk == null ? null : indexOnDisk.eTag, index.values());
|
||||||
channel.truncate(0);
|
channel.truncate(0);
|
||||||
OutputStream os = Channels.newOutputStream(channel);
|
OutputStream os = Channels.newOutputStream(channel);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.util.UUID;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yushijinhun
|
* @author yushijinhun
|
||||||
@@ -49,4 +50,12 @@ public final class JsonUtils {
|
|||||||
throw new JsonParseException("Json object cannot be null.");
|
throw new JsonParseException("Json object cannot be null.");
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> T fromMaybeMalformedJson(String json, Class<T> classOfT) throws JsonParseException {
|
||||||
|
try {
|
||||||
|
return GSON.fromJson(json, classOfT);
|
||||||
|
} catch (JsonSyntaxException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user