PMD-jPinpoint-rules
PMD-jPinpoint-rules copied to clipboard
Request for fix: Kotlin HttpClientBuilderWithoutDisableConnectionState fails with XPathException
This is with latest pmd-7.0.0-SNAPSHOT build with Kotlin support:
For this code:
fun getSomething(): Something {
return Something(Other.create())
}
The Kotlin HttpClientBuilderWithoutDisableConnectionState fails with XPathException: Effective boolean value is not defined for a sequence of two or more items starting with a boolean.
./run.sh pmd \
-R /Users/.../.../git/PMD-jPinpoint-rules/rulesets/kotlin/jpinpoint-kotlin-rules.xml \
-d /Users/.../.../git/apps/.../src \
-f text
Shows:
[main] INFO net.sourceforge.pmd.PMD - Log level is at INFO
[main] WARN net.sourceforge.pmd.PMD - This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/latest/pmd_userdocs_incremental_analysis.html
[main] WARN net.sourceforge.pmd.lang.rule.xpath.Attribute - Use of deprecated attribute 'ImportHeader/@joinTokenText' by XPath rule 'AvoidDeprecatedHystrix' (in ruleset 'jpinpoint-kotlin-rules')
[main] WARN net.sourceforge.pmd.lang.rule.internal.RuleApplicator - Exception applying rule HttpClientBuilderWithoutDisableConnectionState on file /Users/.../.../git/apps/.../src/test/kotlin/com/.../api/.../MockData.kt, continuing with next rule
net.sourceforge.pmd.lang.rule.xpath.PmdXPathException: net.sf.saxon.trans.XPathException: Effective boolean value is not defined for a sequence of two or more items starting with a boolean
Exception Context:
[1:Kind=Type error]
[2:Phase=EVALUATION]
[3:Expression=(:locally created http client builder without disableConnectionState :)
//PostfixUnarySuffix//SimpleIdentifier/T-Identifier[@Text="custom"
and ancestor::PostfixUnaryExpression/PrimaryExpression/SimpleIdentifier/T-Identifier/@Text="HttpClients"
and not(ancestor::PostfixUnaryExpression/PostfixUnarySuffix/NavigationSuffix/SimpleIdentifier/T-Identifier/@Text="disableConnectionState")]
,
//PostfixUnarySuffix//SimpleIdentifier/T-Identifier[@Text="create"
and ancestor::PostfixUnaryExpression/PrimaryExpression/SimpleIdentifier/T-Identifier/(@Text="HttpClientBuilder" or @Text="HttpAsyncClientBuilder")
and not(ancestor::PostfixUnaryExpression/PostfixUnarySuffix/NavigationSuffix/SimpleIdentifier/T-Identifier/@Text="disableConnectionState")]
,
(: method param http client builder without disableConnectionState :)
//FunctionValueParameter/Parameter/Type/TypeReference/UserType/SimpleUserType/SimpleIdentifier/T-Identifier[(@Text="HttpClients" or @Text="HttpClientBuilder" or @Text="HttpAsyncClientBuilder")
and not(ancestor::FunctionDeclaration//PostfixUnarySuffix/NavigationSuffix/SimpleIdentifier/T-Identifier/@Text="disableConnectionState")]]
[4:Version=3.1]
[5:Location in expr=; SystemID: ; Line#: 7; Column#: 40]
[6:Rule=HttpClientBuilderWithoutDisableConnectionState]
[7:Rule applied on node=net.sourceforge.pmd.lang.kotlin.ast.KotlinParser$KtKotlinFile@5a7143b8]
---------------------------------
at net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery.wrapException(SaxonXPathRuleQuery.java:149)
at net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery.evaluate(SaxonXPathRuleQuery.java:142)
at net.sourceforge.pmd.lang.rule.XPathRule.apply(XPathRule.java:130)
at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex(RuleApplicator.java:69)
at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.apply(RuleApplicator.java:52)
at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:140)
at net.sourceforge.pmd.processor.PmdRunnable.processSource(PmdRunnable.java:152)
at net.sourceforge.pmd.processor.PmdRunnable.run(PmdRunnable.java:87)
at net.sourceforge.pmd.processor.MonoThreadProcessor.processFiles(MonoThreadProcessor.java:28)
at net.sourceforge.pmd.PmdAnalysis.performAnalysisImpl(PmdAnalysis.java:306)
at net.sourceforge.pmd.PmdAnalysis.performAnalysisImpl(PmdAnalysis.java:272)
at net.sourceforge.pmd.PmdAnalysis.performAnalysis(PmdAnalysis.java:252)
at net.sourceforge.pmd.PmdAnalysis.runAndReturnStats(PmdAnalysis.java:414)
at net.sourceforge.pmd.PMD.runPmd(PMD.java:204)
at net.sourceforge.pmd.PMD.runPmd(PMD.java:174)
at net.sourceforge.pmd.PMD.main(PMD.java:129)
Caused by: net.sf.saxon.trans.XPathException: Effective boolean value is not defined for a sequence of two or more items starting with a boolean
at net.sf.saxon.expr.parser.ExpressionTool.ebvError(ExpressionTool.java:866)
at net.sf.saxon.expr.parser.ExpressionTool.effectiveBooleanValue(ExpressionTool.java:780)
at net.sf.saxon.expr.Expression.effectiveBooleanValue(Expression.java:890)
at net.sf.saxon.expr.AndExpression.effectiveBooleanValue(AndExpression.java:149)
at net.sf.saxon.expr.AndExpression.effectiveBooleanValue(AndExpression.java:149)
at net.sf.saxon.expr.FilterIterator$NonNumeric.matches(FilterIterator.java:180)
at net.sf.saxon.expr.FilterIterator.getNextMatchingItem(FilterIterator.java:77)
at net.sf.saxon.expr.FilterIterator.next(FilterIterator.java:63)
at [net.sf.saxon.om](http://net.sf.saxon.om/).SequenceIterator.forEachOrFail(SequenceIterator.java:135)
at net.sf.saxon.expr.sort.DocumentOrderIterator.<init>(DocumentOrderIterator.java:49)
at net.sf.saxon.expr.sort.DocumentSorter.iterate(DocumentSorter.java:268)
at net.sf.saxon.expr.instruct.BlockIterator.next(BlockIterator.java:50)
at net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery.evaluate(SaxonXPathRuleQuery.java:127)
... 14 more
[main] WARN net.sourceforge.pmd.lang.rule.internal.RuleApplicator - Exception occurred on node net.sourceforge.pmd.lang.kotlin.ast.KotlinParser$KtKotlinFile@5a7143b8
The issue was using
T-Identifier/(@Text="HttpClientBuilder" or @Text="HttpAsyncClientBuilder")
and not(ancestor...
And error went away when putting this is square brackets instead:
T-Identifier[(@Text="HttpClientBuilder" or @Text="HttpAsyncClientBuilder")
and not(ancestor
See details in commit file remoting.xml in the PR #226
This fix does not seem to be used in production.