GeezerVison is showing github.com — [java] CloseResource rule throws exception on spaces in property types · Issue #3089 · pmd/pmd
[java] CloseResource rule throws exception on spaces in property types #3089
Labels
a:bugPMD crashes or fails to analyse a file. Description
Affects PMD Version:
6.31.0
Worked in earlier versions.
Description:
Processing of rule CloseResource fails with PMDException when types property (which is a list of Java classes) has extraneous spaces between commas.
<rule ref="category/java/errorprone.xml/CloseResource">
<properties>
<property name="closeTargets" value="close"/>
<property name="types" value="java.sql.Connection , java.sql.Statement , java.sql.ResultSet "/>
<property name="closeAsDefaultTarget" value="true"/>
<property name="allowedResourceTypes" value="java.io.ByteArrayOutputStream | java.io.ByteArrayInputStream | java.io.StringWriter | java.io.CharArrayWriter | java.util.stream.Stream | java.util.stream.IntStream | java.util.stream.LongStream | java.util.stream.DoubleStream"/>
<property name="closeNotInFinally" value="true"/>
</properties>
</rule>
Exception Stacktrace:
/data/data/com.termux/files/home/DSAlgos/src/test/java/ds/tests/SinglyLinkedListTest.java: IllegalArgumentException: Not a Java binary name ' java.sql.Statement '
java.lang.IllegalArgumentException: Not a Java binary name ' java.sql.Statement '
at net.sourceforge.pmd.internal.util.AssertionUtil.assertValidJavaBinaryName(AssertionUtil.java:33)
at
net.sourceforge.pmd.lang.java.types.TypeTestUtil.isA(TypeTestUtil.java:100) at
net.sourceforge.pmd.lang.java.rule.errorprone.CloseResourceRule.isNodeInstanceOfResourceType(CloseResourceRule.java:352) at
net.sourceforge.pmd.lang.java.rule.errorprone.CloseResourceRule.visit(CloseResourceRule.java:644)
at
net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix.jjtAccept(ASTPrimaryPrefix.java:48) at
net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220) at
net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:607) at
net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression.jjtAccept(ASTPrimaryExpression.java:25)
at
net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220) at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:337) at net.sourceforge.pmd.lang.java.ast.ASTMemberValue.jjtAccept(ASTMemberValue.java:40) at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220) at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:322) at net.sourceforge.pmd.lang.java.ast.ASTSingleMemberAnnotation.jjtAccept(ASTSingleMemberAnnotation.java:37)
at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220) at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:307) at net.sourceforge.pmd.lang.java.ast.ASTAnnotation.jjtAccept(ASTAnnotation.java:108) at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220) at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:417) at net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration.jjtAccept(ASTTypeDeclaration.java:39)
at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:220) at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visit(AbstractJavaRule.java:392) at net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit.jjtAccept(ASTCompilationUnit.java:44)
at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visitAll(AbstractJavaRule.java:163) at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply(AbstractJavaRule.java:157) at net.sourceforge.pmd.lang.rule.AbstractDelegateRule.apply(AbstractDelegateRule.java:336) at net.sourceforge.pmd.RuleSet.apply(RuleSet.java:659)
at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:163)
at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:200) at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:113)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:95)
at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:57)
at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:85)
at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:29)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834)
Steps to reproduce:
mvn -X pmd:pmd
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Activity
oowekyala commented on Jan 31, 2021
linusjf commented on Jan 31, 2021
@oowekyala Evidently, something changed. IMO, there ought to be no whitespace, trailing or leading. Validating the properties is the best way to handle it. This should remain open until it's fixed in PMD 7.0.0. The workaround for now is to ensure no whitespace is present in properties.
oowekyala commented on Feb 11, 2021
This should remain open until it's fixed in PMD 7.0.0.
Validating properties sure is a better long-term solution, let's add this to #1432 so that this ticket may be closed (since it's specific to CloseResource)
linusjf commented on Feb 11, 2021
This should remain open until it's fixed in PMD 7.0.0.
Validating properties sure is a better long-term solution, let's add this to #1432 so that this ticket may be closed (since it's specific to CloseResource)
As long as it's tracked in an open issue and then only fixed. There were a couple of instances of issues closed because they were to be fixed in PMD 7.0.0 only to have users re-open them. Hence, my response. You don't wish to have that happen once more.
oowekyala commented on Feb 12, 2021
Yes but here this is not the case, since I want to fix the regression for PMD 6.32
added a commit that references this issue
on Feb 26, 2021This issue will close once commit 27f007c is merged into the 'main' branch.27f007c
Metadata
Metadata
a:bugPMD crashes or fails to analyse a file. Development
No branches or pull requestsIssue actions