You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "laimis (via GitHub)" <gi...@apache.org> on 2023/04/13 17:13:25 UTC

[GitHub] [lucenenet] laimis opened a new pull request, #828: Workaround for virtual call issue for WithinPrefixTreeFilter

laimis opened a new pull request, #828:
URL: https://github.com/apache/lucenenet/pull/828

   Continuation of fixes with virtual calls being made from constructors. The issue originally reported by SonarCloud scans: https://sonarcloud.io/project/issues?resolved=false&rules=csharpsquid%3AS1699&id=apache_lucenenet and referenced in this issue: https://github.com/apache/lucenenet/issues/670
   
   This one focuses on WithinPrefixTreeFilter. The fix was to add a protected constructor that does not call virtual methods, and the subclasses can use it to initialize and then call any methods they need inside their constructors.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [lucenenet] NightOwl888 commented on a diff in pull request #828: Workaround for virtual call issue for WithinPrefixTreeFilter

Posted by "NightOwl888 (via GitHub)" <gi...@apache.org>.
NightOwl888 commented on code in PR #828:
URL: https://github.com/apache/lucenenet/pull/828#discussion_r1165900327


##########
src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs:
##########
@@ -50,28 +51,40 @@ public class WithinPrefixTreeFilter : AbstractVisitingPrefixTreeFilter
         //  minimal query buffer by looking in a DocValues cache holding a representative
         //  point of each disjoint component of a document's shape(s).
 
-        private readonly IShape? bufferedQueryShape;//if null then the whole world
+        // LUCENENET specific - made protected to allow subclasses to access if needed
+        protected readonly IShape? m_bufferedQueryShape;//if null then the whole world
 
         /// <summary>
         /// See <see cref="AbstractVisitingPrefixTreeFilter(IShape, string, SpatialPrefixTree, int, int)"/>.
         /// <c>queryBuffer</c> is the (minimum) distance beyond the query shape edge
         /// where non-matching documents are looked for so they can be excluded. If
         /// -1 is used then the whole world is examined (a good default for correctness).
         /// </summary>
+        [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")]
         public WithinPrefixTreeFilter(IShape queryShape, string fieldName, SpatialPrefixTree grid, 
                                       int detailLevel, int prefixGridScanLevel, double queryBuffer)
-            : base(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel)
+            : this(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel, bufferShape: null)
         {
             if (queryBuffer == -1)
             {
-                bufferedQueryShape = null;
+                m_bufferedQueryShape = null;
             }
             else
             {
-                bufferedQueryShape = BufferShape(queryShape, queryBuffer);
+                m_bufferedQueryShape = BufferShape(queryShape, queryBuffer);
             }
         }
 
+        // LUCENENET specific - subclasses can use this class to override the behavior of
+        // BufferShape method in a way that's safe and called from the subclass constructor
+        protected WithinPrefixTreeFilter(IShape queryShape, string fieldName, SpatialPrefixTree grid, 
+                                      int detailLevel, int prefixGridScanLevel, IShape? bufferShape)

Review Comment:
   Let's rename this to `bufferedQueryShape` to match the original field name.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [lucenenet] laimis commented on a diff in pull request #828: Workaround for virtual call issue for WithinPrefixTreeFilter

Posted by "laimis (via GitHub)" <gi...@apache.org>.
laimis commented on code in PR #828:
URL: https://github.com/apache/lucenenet/pull/828#discussion_r1165920038


##########
src/Lucene.Net.Spatial/Prefix/WithinPrefixTreeFilter.cs:
##########
@@ -50,28 +51,40 @@ public class WithinPrefixTreeFilter : AbstractVisitingPrefixTreeFilter
         //  minimal query buffer by looking in a DocValues cache holding a representative
         //  point of each disjoint component of a document's shape(s).
 
-        private readonly IShape? bufferedQueryShape;//if null then the whole world
+        // LUCENENET specific - made protected to allow subclasses to access if needed
+        protected readonly IShape? m_bufferedQueryShape;//if null then the whole world
 
         /// <summary>
         /// See <see cref="AbstractVisitingPrefixTreeFilter(IShape, string, SpatialPrefixTree, int, int)"/>.
         /// <c>queryBuffer</c> is the (minimum) distance beyond the query shape edge
         /// where non-matching documents are looked for so they can be excluded. If
         /// -1 is used then the whole world is examined (a good default for correctness).
         /// </summary>
+        [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")]
         public WithinPrefixTreeFilter(IShape queryShape, string fieldName, SpatialPrefixTree grid, 
                                       int detailLevel, int prefixGridScanLevel, double queryBuffer)
-            : base(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel)
+            : this(queryShape, fieldName, grid, detailLevel, prefixGridScanLevel, bufferShape: null)
         {
             if (queryBuffer == -1)
             {
-                bufferedQueryShape = null;
+                m_bufferedQueryShape = null;
             }
             else
             {
-                bufferedQueryShape = BufferShape(queryShape, queryBuffer);
+                m_bufferedQueryShape = BufferShape(queryShape, queryBuffer);
             }
         }
 
+        // LUCENENET specific - subclasses can use this class to override the behavior of
+        // BufferShape method in a way that's safe and called from the subclass constructor
+        protected WithinPrefixTreeFilter(IShape queryShape, string fieldName, SpatialPrefixTree grid, 
+                                      int detailLevel, int prefixGridScanLevel, IShape? bufferShape)

Review Comment:
   done!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [lucenenet] laimis merged pull request #828: Workaround for virtual call issue for WithinPrefixTreeFilter

Posted by "laimis (via GitHub)" <gi...@apache.org>.
laimis merged PR #828:
URL: https://github.com/apache/lucenenet/pull/828


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org