diff options
Diffstat (limited to 'luni/src/main/java/libcore/io/DiskLruCache.java')
-rw-r--r-- | luni/src/main/java/libcore/io/DiskLruCache.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/luni/src/main/java/libcore/io/DiskLruCache.java b/luni/src/main/java/libcore/io/DiskLruCache.java index fa26624..8338983 100644 --- a/luni/src/main/java/libcore/io/DiskLruCache.java +++ b/luni/src/main/java/libcore/io/DiskLruCache.java @@ -458,9 +458,14 @@ public final class DiskLruCache implements Closeable { // if this edit is creating the entry for the first time, every index must have a value if (success && !entry.readable) { for (int i = 0; i < valueCount; i++) { + if (!editor.written[i]) { + editor.abort(); + throw new IllegalStateException("Newly created entry didn't create value for index " + i); + } if (!entry.getDirtyFile(i).exists()) { editor.abort(); - throw new IllegalStateException("edit didn't create file " + i); + System.logW("DiskLruCache: Newly created entry doesn't have file for index " + i); + return; } } } @@ -659,10 +664,12 @@ public final class DiskLruCache implements Closeable { */ public final class Editor { private final Entry entry; + private final boolean[] written; private boolean hasErrors; private Editor(Entry entry) { this.entry = entry; + this.written = (entry.readable) ? null : new boolean[valueCount]; } /** @@ -702,6 +709,9 @@ public final class DiskLruCache implements Closeable { if (entry.currentEditor != this) { throw new IllegalStateException(); } + if (!entry.readable) { + written[index] = true; + } return new FaultHidingOutputStream(new FileOutputStream(entry.getDirtyFile(index))); } } |