Skip to content

Commit 6e9915f

Browse files
committed
Fix FST not readable error in test
1 parent 98a9d90 commit 6e9915f

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

lucene/core/src/java/org/apache/lucene/util/fst/FST.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ public FST(FSTMetadata<T> metadata, DataInput in, FSTStore fstStore) throws IOEx
417417

418418
/** Create the FST with a metadata object and a FSTReader. */
419419
public FST(FSTMetadata<T> metadata, FSTReader fstReader) {
420+
assert metadata != null;
420421
this.metadata = metadata;
421422
this.outputs = metadata.outputs;
422423
this.fstReader = fstReader;

lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,15 @@ private FSTCompiler(
176176
}
177177

178178
// Get the respective FSTReader of the DataOutput. If the DataOutput is also a FSTReader then we
179-
// will use it, otherwise we will return null.
179+
// will use it, otherwise we will throw an exception.
180+
181+
/**
182+
* Get the respective {@link FSTReader} of the {@link DataOutput}. If the DataOutput is also a
183+
* FSTReader then we will use it, otherwise we will throw an exception.
184+
*
185+
* @return the DataOutput as FSTReader
186+
* @throws IllegalStateException if the DataOutput does not implement FSTReader
187+
*/
180188
public FSTReader getFSTReader() {
181189
if (dataOutput instanceof FSTReader) {
182190
return (FSTReader) dataOutput;

lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,6 @@ public void testNonFinalStopNode() throws Exception {
12521252
final Long nothing = outputs.getNoOutput();
12531253
final FSTCompiler<Long> fstCompiler =
12541254
new FSTCompiler.Builder<>(FST.INPUT_TYPE.BYTE1, outputs).build();
1255-
final FST<Long> fst = fstCompiler.fst;
12561255

12571256
final FSTCompiler.UnCompiledNode<Long> rootNode =
12581257
new FSTCompiler.UnCompiledNode<>(fstCompiler, 0);
@@ -1285,6 +1284,8 @@ public void testNonFinalStopNode() throws Exception {
12851284

12861285
fstCompiler.finish(fstCompiler.addNode(rootNode));
12871286

1287+
final FST<Long> fst = new FST<>(fstCompiler.fst.metadata, fstCompiler.getFSTReader());
1288+
12881289
StringWriter w = new StringWriter();
12891290
// Writer w = new OutputStreamWriter(new FileOutputStream("/x/tmp3/out.dot"));
12901291
Util.toDot(fst, w, false, false);

lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,10 @@ public void build(InputIterator iterator) throws IOException {
586586
fstCompiler.add(scratchInts.get(), outputs.newPair(cost, br));
587587
}
588588
}
589-
fst = new FST<>(fstCompiler.compile(), fstCompiler.getFSTReader());
589+
FST.FSTMetadata<Pair<Long, BytesRef>> fstMetadata = fstCompiler.compile();
590+
if (fstMetadata != null) {
591+
fst = new FST<>(fstMetadata, fstCompiler.getFSTReader());
592+
}
590593
count = newCount;
591594

592595
// Util.dotToFile(fst, "/tmp/suggest.dot");

lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ public void build(InputIterator iterator) throws IOException {
126126
previous.copyBytes(scratch);
127127
newCount++;
128128
}
129-
fst = new FST<>(fstCompiler.compile(), fstCompiler.getFSTReader());
129+
FST.FSTMetadata<Long> fstMetadata = fstCompiler.compile();
130+
if (fstMetadata != null) {
131+
fst = new FST<>(fstMetadata, fstCompiler.getFSTReader());
132+
}
130133
count = newCount;
131134
}
132135

0 commit comments

Comments
 (0)