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

Adjust QueryTemplateManager to allow subclasses avoid calling virtual methods from the constructors #829

Conversation

laimis
Copy link
Contributor

@laimis laimis commented Apr 13, 2023

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: #670

This one focuses on queryTemplateManager where we allow subclasses to use default constructor and expose m_defaultCompiledTemplates as protected for them to initialize it when needed.

@laimis laimis requested a review from NightOwl888 April 13, 2023 17:24
@@ -34,20 +35,28 @@ namespace Lucene.Net.QueryParsers.Xml
public class QueryTemplateManager
{
private readonly IDictionary<string, XslCompiledTransform> compiledTemplatesCache = new Dictionary<string, XslCompiledTransform>(); // LUCENENET: marked readonly
private XslCompiledTransform defaultCompiledTemplates;
// LUCENENET specific - made protected to allow subclasses to access and initialize
protected XslCompiledTransform m_defaultCompiledTemplates;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was meant to be a "default template" and the user could subclass to add their own template. To do this they would need to:

  1. Override the public QueryTemplateManager() constructor.
  2. Load their own template. However they want to.
  3. Set their own private XslCompiledTransform to a private variable.
  4. Override GetQueryAsXmlString and GetQueryAsDOM to supply their private variable.

Maybe I have missed something, but I don't think there is any advantage to making this variable protected as it is supposed to represent the "default" template, not the user specified one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok, so basically no need to make this variable protected. Adjusting now...

@laimis laimis requested a review from NightOwl888 April 13, 2023 19:03
@laimis laimis merged commit a51aa50 into apache:master Apr 13, 2023
@laimis laimis deleted the fix/virtual-calls-from-constructors-querytemplatemanager branch April 13, 2023 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants