Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Fix/virtual calls from constructors for cell #808

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Lucene.Net.Spatial/Prefix/Tree/Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ protected Cell(SpatialPrefixTree spatialPrefixTree, string token)
if (token.Length > 0 && token[token.Length - 1] == (char)LEAF_BYTE)
{
this.token = token.Substring(0, (token.Length - 1) - 0);
SetLeaf();
// LUCENENET specific - calling private instead of virtual to avoid initialization issues
SetLeafInternal();
}
if (Level == 0)
{
Expand Down Expand Up @@ -157,7 +158,9 @@ private void B_fixLeaf()
if (bytes![b_off + b_len - 1] == LEAF_BYTE)
{
b_len--;
SetLeaf();
// LUCENENET specific - calling internal vs virtual
// to avoid issues when this is called from constructor
SetLeafInternal();
}
else
{
Expand All @@ -175,7 +178,11 @@ private void B_fixLeaf()
public virtual bool IsLeaf => m_leaf;

/// <summary>Note: not supported at level 0.</summary>
public virtual void SetLeaf()
public virtual void SetLeaf() => SetLeafInternal();

// LUCENENET specific - S1699 - private method that can be called
// from constructor without causing initialization issues
private void SetLeafInternal()
{
if (Debugging.AssertsEnabled) Debugging.Assert(Level != 0);
m_leaf = true;
Expand Down
11 changes: 7 additions & 4 deletions src/Lucene.Net/Search/DisjunctionMaxQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public DisjunctionMaxQuery(float tieBreakerMultiplier)
public DisjunctionMaxQuery(ICollection<Query> disjuncts, float tieBreakerMultiplier)
{
this.tieBreakerMultiplier = tieBreakerMultiplier;
Add(disjuncts);
AddInternal(disjuncts); // LUCENENET specific - calling private instead of virtual
}

/// <summary>
Expand All @@ -101,10 +101,13 @@ public virtual void Add(Query query)
/// Add a collection of disjuncts to this disjunction
/// via <see cref="T:IEnumerable{Query}"/> </summary>
/// <param name="disjuncts"> A collection of queries to add as disjuncts. </param>
public virtual void Add(ICollection<Query> disjuncts)
{
public virtual void Add(ICollection<Query> disjuncts) =>
AddInternal(disjuncts);

// LUCENENET specific - S1699 - introduced private AddInternal that
// is called from virtual Add and constructor
private void AddInternal(ICollection<Query> disjuncts) =>
this.disjuncts.AddRange(disjuncts);
}

/// <returns> An <see cref="T:IEnumerator{Query}"/> over the disjuncts </returns>
public virtual IEnumerator<Query> GetEnumerator()
Expand Down