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
AvoidRecompilingXPathExpression for Kotlin #295
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some remarks, which we partially discussed already... maybe you want to clarify/fix, but otherwise merge is fine
…atAsField' into kotlin/AvoidRecompilingXPathExpression # Conflicts: # src/main/resources/category/kotlin/common.xml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions, otherwise good to merge!
Hope use of ThreadLocals will not impact future code bases that use reactive style or virtual threads.
<priority>2</priority> | ||
<properties> | ||
<property name="tag" value="jpinpoint-rule" type="String" description="for-sonar"/> | ||
<property name="version" value="2.0"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 3.1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
class AvoidRecompilingXPathExpressionKotlin { | ||
fun bad1(doc: Document?): NodeList { | ||
val xpath: XPath = XPathFactory.newInstance().newXPath() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also have a rule to flag use of XPath.newInstance() each time? Also preferred to move to ThreadLocal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No we don't have it at the moment. Might be useful.
<priority>2</priority> | ||
<properties> | ||
<property name="tag" value="jpinpoint-rule" type="String" description="for-sonar"/> | ||
<property name="version" value="2.0"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also move to 3.1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also remove version attribute
} catch (e: XPathExpressionException) { | ||
throw RuntimeException(e) | ||
} | ||
tlExpr = ThreadLocal.withInitial { expr } // good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule does not check for use in ThreadLocal... probably compile call is only checked in FunctionBody, thus allowed in init block. Is good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, FunctionBody is used in the rule xpath expression. And I think good enough.
…lingXPathExpression # Conflicts: # docs/EvaluateRulesForKotlin.md # src/main/resources/category/kotlin/common.xml
Quality Gate passedIssues Measures |
AvoidRecompilingXPathExpression for Kotlin.
Note a code example of the good solution is TODO, the Java example is with ThreadLocals, unclear how this works for Kotlin.