Skip to content

Commit 45aa971

Browse files
committed
Lucene.Net.Analysis.Phonetic.Language.DoubleMetaphone.MaxCodeLen: Added guard clause to ensure the value passed in is not negative, otherwise TestRandomChains could fail.
1 parent f45df9a commit 45aa971

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/Lucene.Net.Analysis.Phonetic/DoubleMetaphoneFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public sealed class DoubleMetaphoneFilter : TokenFilter
4747
public DoubleMetaphoneFilter(TokenStream input, int maxCodeLength, bool inject)
4848
: base(input)
4949
{
50-
this.encoder.MaxCodeLen = maxCodeLength;
50+
this.encoder.MaxCodeLen = maxCodeLength; // LUCENENET: MaxCodeLen ensures the value is non-negative
5151
this.inject = inject;
5252
this.termAtt = AddAttribute<ICharTermAttribute>();
5353
this.posAtt = AddAttribute<IPositionIncrementAttribute>();

src/Lucene.Net.Analysis.Phonetic/Language/DoubleMetaphone.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,13 @@ public virtual bool IsDoubleMetaphoneEqual(string value1, string value2, bool al
242242
public virtual int MaxCodeLen
243243
{
244244
get => this.maxCodeLen;
245-
set => this.maxCodeLen = value;
245+
set
246+
{
247+
// LUCENENET: Added guard clause
248+
if (value < 0)
249+
throw new ArgumentOutOfRangeException(nameof(value), "maxCodeLen must be a non-negative integer");
250+
this.maxCodeLen = value;
251+
}
246252
}
247253

248254
//-- BEGIN HANDLERS --//

0 commit comments

Comments
 (0)