MapDBLog: add sanity check
Change-Id: If364a073b2d80c301eed236f80c6884f34bee6be
Showing
1 changed file
with
7 additions
and
5 deletions
| ... | @@ -99,7 +99,8 @@ public class MapDBLog implements Log { | ... | @@ -99,7 +99,8 @@ public class MapDBLog implements Log { |
| 99 | long nextIndex = log.isEmpty() ? 1 : log.lastKey() + 1; | 99 | long nextIndex = log.isEmpty() ? 1 : log.lastKey() + 1; |
| 100 | long addedBytes = 0; | 100 | long addedBytes = 0; |
| 101 | for (Entry entry : entries) { | 101 | for (Entry entry : entries) { |
| 102 | - byte[] entryBytes = serializer.encode(entry); | 102 | + byte[] entryBytes = verifyNotNull(serializer.encode(entry), |
| 103 | + "Writing LogEntry %s failed", nextIndex); | ||
| 103 | log.put(nextIndex, entryBytes); | 104 | log.put(nextIndex, entryBytes); |
| 104 | addedBytes += entryBytes.length; | 105 | addedBytes += entryBytes.length; |
| 105 | indices.add(nextIndex); | 106 | indices.add(nextIndex); |
| ... | @@ -144,7 +145,7 @@ public class MapDBLog implements Log { | ... | @@ -144,7 +145,7 @@ public class MapDBLog implements Log { |
| 144 | DB db = txMaker.makeTx(); | 145 | DB db = txMaker.makeTx(); |
| 145 | try { | 146 | try { |
| 146 | BTreeMap<Long, byte[]> log = getLogMap(db); | 147 | BTreeMap<Long, byte[]> log = getLogMap(db); |
| 147 | - return log.isEmpty() ? null : serializer.decode(log.firstEntry().getValue()); | 148 | + return log.isEmpty() ? null : verifyNotNull(serializer.decode(log.firstEntry().getValue())); |
| 148 | } finally { | 149 | } finally { |
| 149 | db.close(); | 150 | db.close(); |
| 150 | } | 151 | } |
| ... | @@ -177,7 +178,7 @@ public class MapDBLog implements Log { | ... | @@ -177,7 +178,7 @@ public class MapDBLog implements Log { |
| 177 | } | 178 | } |
| 178 | List<T> entries = new ArrayList<>((int) (to - from + 1)); | 179 | List<T> entries = new ArrayList<>((int) (to - from + 1)); |
| 179 | for (long i = from; i <= to; i++) { | 180 | for (long i = from; i <= to; i++) { |
| 180 | - T entry = serializer.decode(log.get(i)); | 181 | + T entry = verifyNotNull(serializer.decode(log.get(i)), "LogEntry %s was null", i); |
| 181 | entries.add(entry); | 182 | entries.add(entry); |
| 182 | } | 183 | } |
| 183 | return entries; | 184 | return entries; |
| ... | @@ -193,7 +194,8 @@ public class MapDBLog implements Log { | ... | @@ -193,7 +194,8 @@ public class MapDBLog implements Log { |
| 193 | try { | 194 | try { |
| 194 | BTreeMap<Long, byte[]> log = getLogMap(db); | 195 | BTreeMap<Long, byte[]> log = getLogMap(db); |
| 195 | byte[] entryBytes = log.get(index); | 196 | byte[] entryBytes = log.get(index); |
| 196 | - return entryBytes == null ? null : serializer.decode(entryBytes); | 197 | + return entryBytes == null ? null : verifyNotNull(serializer.decode(entryBytes), |
| 198 | + "LogEntry %s was null", index); | ||
| 197 | } finally { | 199 | } finally { |
| 198 | db.close(); | 200 | db.close(); |
| 199 | } | 201 | } |
| ... | @@ -217,7 +219,7 @@ public class MapDBLog implements Log { | ... | @@ -217,7 +219,7 @@ public class MapDBLog implements Log { |
| 217 | DB db = txMaker.makeTx(); | 219 | DB db = txMaker.makeTx(); |
| 218 | try { | 220 | try { |
| 219 | BTreeMap<Long, byte[]> log = getLogMap(db); | 221 | BTreeMap<Long, byte[]> log = getLogMap(db); |
| 220 | - return log.isEmpty() ? null : serializer.decode(log.lastEntry().getValue()); | 222 | + return log.isEmpty() ? null : verifyNotNull(serializer.decode(log.lastEntry().getValue())); |
| 221 | } finally { | 223 | } finally { |
| 222 | db.close(); | 224 | db.close(); |
| 223 | } | 225 | } | ... | ... |
-
Please register or login to post a comment