Skip to content

[core] "Unable to create ValueRepresentation" when using @LiteralText (XPath) #6330

@Vampire

Description

@Vampire

Affects PMD Version: 7.19.0

Description:

I configured the XPath rule given below and got the mentioned exception during analysis.

Exception Stacktrace:

Exception applying rule UseAsManyArgumentsAsPlaceholdersInLogMethod on file [...], continuing with next rule
org.apache.commons.lang3.exception.ContextedRuntimeException: java.lang.RuntimeException: Unable to create ValueRepresentation for value of type: class net.sourceforge.pmd.lang.document.Chars
Exception Context:
	[1:Rule applied on node=!debug only! [MethodCall:113:17]logger.atInfo().log("Got no {} restrictions injected")]
---------------------------------
	at net.sourceforge.pmd.util.AssertionUtil.contexted(AssertionUtil.java:256)
	at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex(RuleApplicator.java:79)
	at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.apply(RuleApplicator.java:57)
	at net.sourceforge.pmd.lang.rule.internal.RuleSets.apply(RuleSets.java:183)
	at net.sourceforge.pmd.lang.impl.PmdRunnable.processSource(PmdRunnable.java:140)
	at net.sourceforge.pmd.lang.impl.PmdRunnable.run(PmdRunnable.java:80)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.RuntimeException: Unable to create ValueRepresentation for value of type: class net.sourceforge.pmd.lang.document.Chars
	at net.sourceforge.pmd.lang.rule.xpath.internal.DomainConversion.getAtomicRepresentation(DomainConversion.java:151)
	at net.sourceforge.pmd.lang.rule.xpath.internal.DomainConversion.convert(DomainConversion.java:61)
	at net.sourceforge.pmd.lang.rule.xpath.internal.AstAttributeNode.atomize(AstAttributeNode.java:73)
	at net.sf.saxon.tree.iter.AtomizingIterator.next(AtomizingIterator.java:64)
	at net.sf.saxon.tree.iter.AtomizingIterator.next(AtomizingIterator.java:28)
	at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:156)
	at net.sf.saxon.expr.CardinalityCheckingIterator.<init>(CardinalityCheckingIterator.java:55)
	at net.sf.saxon.expr.CardinalityChecker.checkCardinality(CardinalityChecker.java:258)
	at net.sf.saxon.expr.CardinalityChecker$CardinalityCheckerElaborator.lambda$elaborateForPull$0(CardinalityChecker.java:506)
	at net.sf.saxon.expr.elab.LazyPullEvaluator.evaluate(LazyPullEvaluator.java:39)
	at net.sf.saxon.expr.FunctionCall$FunctionCallElaborator.evaluateArguments(FunctionCall.java:671)
	at net.sf.saxon.expr.SystemFunctionCall$SystemFunctionCallElaborator.lambda$elaborateForPull$3(SystemFunctionCall.java:628)
	at net.sf.saxon.functions.Count$CountFnElaborator.lambda$elaborateForItem$0(Count.java:130)
	at net.sf.saxon.expr.ValueComparison$ValueComparisonElaborator.lambda$elaborateForItem$1(ValueComparison.java:546)
	at net.sf.saxon.expr.elab.ItemElaborator.lambda$elaborateForPull$0(ItemElaborator.java:36)
	at net.sf.saxon.expr.FilterExpression$FilterExprElaborator$PositionalFilteredIterator.next(FilterExpression.java:1331)
	at net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery.evaluate(SaxonXPathRuleQuery.java:127)
	at net.sourceforge.pmd.lang.rule.xpath.XPathRule.apply(XPathRule.java:101)
	at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex(RuleApplicator.java:77)
	... 9 more
Exception occurred on node !debug only! [MethodCall:113:17]logger.atInfo().log("Got no {} restrictions injected")

Code Sample demonstrating the issue:

logger.atInfo().log("Got no {} restrictions injected");

Steps to reproduce:

//MethodCall
[@MethodName = "log"]
[
    *[1]/descendant::VariableAccess[pmd-java:typeIs("org.apache.logging.log4j.Logger")]
    or *[1]/descendant-or-self::VariableAccess[pmd-java:typeIs("org.apache.logging.log4j.LogBuilder")]
]
[count(tokenize(ArgumentList/*[1]/self::StringLiteral/@LiteralText, "\{\}")) != count(ArgumentList/*)]

Running PMD through: Gradle

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions