pmd/pmd-eclipse-plugin

The ControlStatementBraces rule throws java.lang.IllegalArgumentException: can't parse argument number

zooltech opened this issue · 1 comments

Eclipse IDE for Enterprise Java Developers Version: 2020-06 (4.16.0) Build id: 20200615-1200
pmd-eclipse-plugin version: 4.16.0

The following java code causes the ControlStatementBraces rule to throw an exception: "java.lang.IllegalArgumentException: can't parse argument number"

         if (size > 1)
            System.out.println("size=" + size);
          else {
              System.out.println("size=" + size);
          }

pmd-eclipse.log:

......

2020/09/03 13:49:16.904 [Worker-21: ReviewCode] WARN  n.s.p.l.r.AbstractRuleChainVisitor - Exception applying rule ControlStatementBraces on file E:\myworks\espace\tetete\src\tetete\TestIf.java, continuing with next rule
java.lang.IllegalArgumentException: can't parse argument number: 
	at java.base/java.text.MessageFormat.makeFormat(MessageFormat.java:1451) ~[na:na]
	at java.base/java.text.MessageFormat.applyPattern(MessageFormat.java:491) ~[na:na]
	at java.base/java.text.MessageFormat.<init>(MessageFormat.java:370) ~[na:na]
	at java.base/java.text.MessageFormat.format(MessageFormat.java:859) ~[na:na]
	at net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory.cleanup(AbstractRuleViolationFactory.java:26) ~[na:na]
	at net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory.addViolation(AbstractRuleViolationFactory.java:35) ~[na:na]
	at net.sourceforge.pmd.lang.rule.AbstractRule.addViolation(AbstractRule.java:359) ~[na:na]
	at net.sourceforge.pmd.lang.rule.XPathRule.evaluate(XPathRule.java:178) ~[na:na]
	at net.sourceforge.pmd.lang.rule.XPathRule.apply(XPathRule.java:158) ~[na:na]
	at net.sourceforge.pmd.lang.internal.DefaultRulechainVisitor.visit(DefaultRulechainVisitor.java:26) ~[na:na]
	at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:99) ~[na:na]
	at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:72) ~[na:na]
	at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:145) ~[na:na]
	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:194) ~[na:na]
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:107) ~[na:na]
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:89) ~[na:na]
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:51) ~[na:na]
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:78) ~[na:na]
	at net.sourceforge.pmd.processor.MonoThreadProcessor.runAnalysis(MonoThreadProcessor.java:29) ~[na:na]
	at net.sourceforge.pmd.processor.AbstractPMDProcessor.processFiles(AbstractPMDProcessor.java:122) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.BaseVisitor.reviewResource(BaseVisitor.java:385) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.ResourceVisitor.visit(ResourceVisitor.java:31) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.lambda$1(Resource.java:117) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.lambda$0(Resource.java:85) ~[na:na]
	at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:85) ~[na:na]
	at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:135) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:55) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:117) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:105) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.processResource(ReviewCodeCmd.java:544) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.processResources(ReviewCodeCmd.java:492) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.execute(ReviewCodeCmd.java:195) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.JobCommandProcessor$1.run(JobCommandProcessor.java:60) ~[na:na]
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63) ~[org.eclipse.core.jobs_3.10.800.v20200421-0950.jar:na]
Caused by: java.lang.NumberFormatException: For input string: ""
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:na]
	at java.base/java.lang.Integer.parseInt(Integer.java:662) ~[na:na]
	at java.base/java.lang.Integer.parseInt(Integer.java:770) ~[na:na]
	at java.base/java.text.MessageFormat.makeFormat(MessageFormat.java:1449) ~[na:na]
	... 34 common frames omitted
2020/09/03 13:49:16.936 [Worker-21: ReviewCode] ERROR n.s.p.e.runtime.cmd.BaseVisitor - PMD exception visiting TestIf.java
net.sourceforge.pmd.PMDException: There were processing errors!
E:\myworks\espace\tetete\src\tetete\TestIf.java: IllegalArgumentException: can't parse argument number:  java.lang.IllegalArgumentException: can't parse argument number: 
	at java.base/java.text.MessageFormat.makeFormat(MessageFormat.java:1451)
	at java.base/java.text.MessageFormat.applyPattern(MessageFormat.java:491)
	at java.base/java.text.MessageFormat.<init>(MessageFormat.java:370)
	at java.base/java.text.MessageFormat.format(MessageFormat.java:859)
	at net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory.cleanup(AbstractRuleViolationFactory.java:26)
	at net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory.addViolation(AbstractRuleViolationFactory.java:35)
	at net.sourceforge.pmd.lang.rule.AbstractRule.addViolation(AbstractRule.java:359)
	at net.sourceforge.pmd.lang.rule.XPathRule.evaluate(XPathRule.java:178)
	at net.sourceforge.pmd.lang.rule.XPathRule.apply(XPathRule.java:158)
	at net.sourceforge.pmd.lang.internal.DefaultRulechainVisitor.visit(DefaultRulechainVisitor.java:26)
	at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:99)
	at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:72)
	at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:145)
	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:194)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:107)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:89)
	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:51)
	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:78)
	at net.sourceforge.pmd.processor.MonoThreadProcessor.runAnalysis(MonoThreadProcessor.java:29)
	at net.sourceforge.pmd.processor.AbstractPMDProcessor.processFiles(AbstractPMDProcessor.java:122)
	at net.sourceforge.pmd.eclipse.runtime.cmd.BaseVisitor.reviewResource(BaseVisitor.java:385)
	at net.sourceforge.pmd.eclipse.runtime.cmd.ResourceVisitor.visit(ResourceVisitor.java:31)
	at org.eclipse.core.internal.resources.Resource.lambda$1(Resource.java:117)
	at org.eclipse.core.internal.resources.Resource.lambda$0(Resource.java:85)
	at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:85)
	at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:135)
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:55)
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:117)
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:105)
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.processResource(ReviewCodeCmd.java:544)
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.processResources(ReviewCodeCmd.java:492)
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.execute(ReviewCodeCmd.java:195)
	at net.sourceforge.pmd.eclipse.runtime.cmd.JobCommandProcessor$1.run(JobCommandProcessor.java:60)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.NumberFormatException: For input string: ""
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.base/java.lang.Integer.parseInt(Integer.java:662)
	at java.base/java.lang.Integer.parseInt(Integer.java:770)
	at java.base/java.text.MessageFormat.makeFormat(MessageFormat.java:1449)
	... 34 more


	at net.sourceforge.pmd.eclipse.runtime.cmd.BaseVisitor.reviewResource(BaseVisitor.java:412) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.ResourceVisitor.visit(ResourceVisitor.java:31) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.lambda$1(Resource.java:117) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.lambda$0(Resource.java:85) ~[na:na]
	at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:85) ~[na:na]
	at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:135) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:55) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:117) ~[na:na]
	at org.eclipse.core.internal.resources.Resource.accept(Resource.java:105) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.processResource(ReviewCodeCmd.java:544) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.processResources(ReviewCodeCmd.java:492) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd.execute(ReviewCodeCmd.java:195) ~[na:na]
	at net.sourceforge.pmd.eclipse.runtime.cmd.JobCommandProcessor$1.run(JobCommandProcessor.java:60) ~[na:na]
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63) ~[org.eclipse.core.jobs_3.10.800.v20200421-0950.jar:na]

......

Thanks for the report.
This problem doesn't appear with the standard ruleset, which means, you probably have customized the rule message.
Please remove or escape the curly braces in the message, as these are placeholders for java.text.MessageFormat.

I could reproduce the exception with the following ruleset:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         name="pmd-eclipse"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
   <description>PMD Plugin preferences rule set</description>

   <rule ref="category/java/codestyle.xml/ControlStatementBraces" message="This statement should have braces ({})"/>

</ruleset>

You can escape the curly braces with single quotes:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         name="pmd-eclipse"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
   <description>PMD Plugin preferences rule set</description>

   <rule ref="category/java/codestyle.xml/ControlStatementBraces" message="This statement should have braces ('{'}')"/>

</ruleset>