#7022 unopened queue was throwing npe

Fixes #7023
This commit is contained in:
Armin Braun 2017-05-04 17:18:04 +02:00
parent 2b3d494bbe
commit 68aa662491
2 changed files with 15 additions and 1 deletions

View file

@ -140,7 +140,14 @@ public class Queue implements Closeable {
}
public long getPersistedByteSize() {
return headPage.getPageIO().getHead() + tailPages.stream().mapToLong((p) -> p.getPageIO().getHead()).sum();
final long size;
if (headPage == null) {
size = 0L;
} else {
size = headPage.getPageIO().getHead()
+ tailPages.stream().mapToLong(p -> p.getPageIO().getHead()).sum();
}
return size;
}
public int getPageCapacity() {

View file

@ -725,4 +725,11 @@ public class QueueTest {
q.close();
}
@Test
public void getsPersistedByteSizeCorrectlyForUnopened() throws Exception {
Settings settings = TestSettings.persistedQueueSettings(100, dataPath);
try (Queue q = new Queue(settings)) {
assertThat(q.getPersistedByteSize(), is(equalTo(0L)));
}
}
}