From fb269c9e64ea08ad46a72002963ced2f18bfc8b9 Mon Sep 17 00:00:00 2001 From: Dzung Bui Date: Sat, 9 Dec 2023 02:59:39 +0900 Subject: [PATCH] Fix NPE on off-heap test and FST is null (#12894) --- .../org/apache/lucene/tests/util/fst/FSTTester.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/fst/FSTTester.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/fst/FSTTester.java index d80cbf58dc4..07f877575b0 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/fst/FSTTester.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/fst/FSTTester.java @@ -283,14 +283,17 @@ public class FSTTester { } } FST fst = fstCompiler.compile(); - ; if (useOffHeap) { indexOutput.close(); - try (IndexInput in = dir.openInput("fstOffHeap.bin", IOContext.DEFAULT)) { - fst = new FST<>(fst.getMetadata(), in); - } finally { + if (fst == null) { dir.deleteFile("fstOffHeap.bin"); + } else { + try (IndexInput in = dir.openInput("fstOffHeap.bin", IOContext.DEFAULT)) { + fst = new FST<>(fst.getMetadata(), in); + } finally { + dir.deleteFile("fstOffHeap.bin"); + } } } else if (random.nextBoolean() && fst != null) { IOContext context = LuceneTestCase.newIOContext(random);