Fix NPE on off-heap test and FST is null (#12894)

This commit is contained in:
Dzung Bui 2023-12-09 02:59:39 +09:00 committed by GitHub
parent 1c4c1c831d
commit fb269c9e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -283,15 +283,18 @@ public class FSTTester<T> {
} }
} }
FST<T> fst = fstCompiler.compile(); FST<T> fst = fstCompiler.compile();
;
if (useOffHeap) { if (useOffHeap) {
indexOutput.close(); indexOutput.close();
if (fst == null) {
dir.deleteFile("fstOffHeap.bin");
} else {
try (IndexInput in = dir.openInput("fstOffHeap.bin", IOContext.DEFAULT)) { try (IndexInput in = dir.openInput("fstOffHeap.bin", IOContext.DEFAULT)) {
fst = new FST<>(fst.getMetadata(), in); fst = new FST<>(fst.getMetadata(), in);
} finally { } finally {
dir.deleteFile("fstOffHeap.bin"); dir.deleteFile("fstOffHeap.bin");
} }
}
} else if (random.nextBoolean() && fst != null) { } else if (random.nextBoolean() && fst != null) {
IOContext context = LuceneTestCase.newIOContext(random); IOContext context = LuceneTestCase.newIOContext(random);
try (IndexOutput out = dir.createOutput("fst.bin", context)) { try (IndexOutput out = dir.createOutput("fst.bin", context)) {