This is an automated email from the ASF dual-hosted git repository.

laimis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git


The following commit(s) were added to refs/heads/master by this push:
     new 6973f6f4c ComposedQuery fix for virtual call being made from 
constructor (#831)
6973f6f4c is described below

commit 6973f6f4cf598acf9fb8aee62395d2db08cb8486
Author: Laimonas Simutis <[email protected]>
AuthorDate: Thu Apr 13 12:31:10 2023 -0700

    ComposedQuery fix for virtual call being made from constructor (#831)
---
 .../Surround/Query/ComposedQuery.cs                    | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/Lucene.Net.QueryParser/Surround/Query/ComposedQuery.cs 
b/src/Lucene.Net.QueryParser/Surround/Query/ComposedQuery.cs
index 33052edf2..2ec79ae6b 100644
--- a/src/Lucene.Net.QueryParser/Surround/Query/ComposedQuery.cs
+++ b/src/Lucene.Net.QueryParser/Surround/Query/ComposedQuery.cs
@@ -1,6 +1,5 @@
-using Lucene.Net.Diagnostics;
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Text;
 using JCG = J2N.Collections.Generic;
 
@@ -28,13 +27,22 @@ namespace Lucene.Net.QueryParsers.Surround.Query
     /// </summary>
     public abstract class ComposedQuery : SrndQuery
     {
-        protected ComposedQuery(IList<SrndQuery> qs, bool operatorInfix, 
string opName) // LUCENENET: CA1012: Abstract types should not have 
constructors (marked protected)
+        // LUCENENET specific - provided protected parameterless constructor 
to allow subclasses
+        // avoid issues with virtual Recompose method
+        protected ComposedQuery(bool operatorInfix, string opName)
         {
-            Recompose(qs);
             this.operatorInfix = operatorInfix;
             this.m_opName = opName;
         }
 
+        [SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary 
suppression", Justification = "This is a SonarCloud issue")]
+        [SuppressMessage("CodeQuality", "S1699:Constructors should only call 
non-overridable methods", Justification = "Required for continuity with 
Lucene's design")]
+        protected ComposedQuery(IList<SrndQuery> qs, bool operatorInfix, 
string opName) // LUCENENET: CA1012: Abstract types should not have 
constructors (marked protected)
+            : this(operatorInfix, opName)
+        {
+            Recompose(qs);
+        }
+
         protected virtual void Recompose(IList<SrndQuery> queries)
         {
             if (queries.Count < 2) throw AssertionError.Create("Too few 
subqueries");

Reply via email to