diff --git a/rulesets/kotlin/jpinpoint-kotlin-rules.xml b/rulesets/kotlin/jpinpoint-kotlin-rules.xml index 9cb2b441..4922536e 100644 --- a/rulesets/kotlin/jpinpoint-kotlin-rules.xml +++ b/rulesets/kotlin/jpinpoint-kotlin-rules.xml @@ -11,6 +11,58 @@ + + + Problem: java.text.DecimalFormat and java.text.ChoiceFormat are thread-unsafe. + Solution: usual solution is to create a new local one when needed in a method. + (jpinpoint-rules) + (jpinpoint-kotlin-rules) + 1 + + + + + + + + + + + + + + XPathExpression is created and compiled on every method call, compiled possibly implicitly by XPath::evaluate. + Problem: Creation of XPath and compilation of XPathExpression takes time. It may slow down your application. + Solution: 1. Avoid XPath usage. 2. Compile the xpath expression as String into a XPathExpression. However, since XPath and XPathExpression classes are thread-unsafe, they are not easily cached. Caching it in a ThreadLocal may be a solution (sure? - TODO) . + (jpinpoint-rules) + 2 + + + + + + + + + + + + 2 - 3 - 1 - + + XPathExpression is created and compiled on every method call, compiled possibly implicitly by XPath::evaluate. + Problem: Creation of XPath and compilation of XPathExpression takes time. It may slow down your application. + Solution: 1. Avoid XPath usage. 2. Compile the xpath expression as String into a XPathExpression. However, since XPath and XPathExpression classes are thread-unsafe, they are not easily cached. Caching it in a ThreadLocal may be a solution. + (jpinpoint-rules) + 2 + + + + + + + + + + init { + val xpath = tlFac.get().newXPath() + val expr: XPathExpression = try { + xpath.compile("//book[author='Isaac Asimov']/title/text()") + } catch (e: XPathExpressionException) { + throw RuntimeException(e) + } + tlExpr = ThreadLocal.withInitial { expr } // good + } + + @Throws(XPathExpressionException::class) + fun good(doc: Document?): NodeList { + return tlExpr!!.get().evaluate(doc, XPathConstants.NODESET) as NodeList // good + } +} + ]]> + + + + + + AvoidRecompilingXPathExpression + 2 + 8, 16 + + + init { + val xpath = tlFac.get().newXPath() + val expr: XPathExpression = try { + xpath.compile("//book[author='Isaac Asimov']/title/text()") + } catch (e: XPathExpressionException) { + throw RuntimeException(e) + } + tlExpr = ThreadLocal.withInitial { expr } // good + } + + @Throws(XPathExpressionException::class) + fun good(doc: Document?): NodeList { + return tlExpr!!.get().evaluate(doc, XPathConstants.NODESET) as NodeList // good + } +} +]]> + + + \ No newline at end of file diff --git a/testkt b/testkt new file mode 100755 index 00000000..f48da4ad --- /dev/null +++ b/testkt @@ -0,0 +1,2 @@ +#!/bin/sh +mvn test -Pkotlin-pmd7