Skip to content

[core] NullPointerException while executing PMD command line --- doPMD #3318

Closed
@linusjf

Description

@linusjf

Affects PMD Version:
6.35.0

Description:
NullPointerException while executing the PMD CLI. Additionally, the CLI must return an exit code other than 0 when it crashes. It doesn't.

Exception Stacktrace:
The PMD CLI throws a NullPointerException while executing the latest version of PMD.
The PMD script is located at:

https://raw.githubusercontent.com/Fernal73/LearnJava/master/pmd

Execute bash -x ./pmd Hello

++ realpath pmdrules.xml
+ declare -r rulesFile=/data/data/com.termux/files/home/LearnJava/pmdrules.xml
+ declare -r cacheFile=pmd.cache
+ declare -r errFile=pmd.errors
+ declare -r auxCpFile=compile.cp
+ auxCp=
+ declare -r setupcp=setupclasspath
+ declare -r format=text
+ declare -i threads=5
+ declare -i minpriority=5
++ realpath pmd.cp
+ declare -r classpathFile=/data/data/com.termux/files/home/LearnJava/pmd.cp
++ cat /data/data/com.termux/files/home/LearnJava/pmd.cp
+ pmdCp=/data/data/com.termux/files/home/LearnJava/lib/antlr4-runtime-4.7.2.jar:/data/data/com.termux/files/home/LearnJava/lib/asm-9.1.jar:/data/data/com.termux/files/home/LearnJava/lib/commons-io-2.6.jar:/data/data/com.termux/files/home/LearnJava/lib/commons-lang3-3.8.1.jar:/data/data/com.termux/files/home/LearnJava/lib/gson-2.8.5.jar:/data/data/com.termux/files/home/LearnJava/lib/jcommander-1.48.jar:/data/data/com.termux/files/home/LearnJava/lib/pmd-core-6.35.0.jar:/data/data/com.termux/files/home/LearnJava/lib/pmd-java-6.35.0.jar:/data/data/com.termux/files/home/LearnJava/lib/pmd-jsp-6.35.0.jar:/data/data/com.termux/files/home/LearnJava/lib/pmd-xml-6.35.0.jar:/data/data/com.termux/files/home/LearnJava/lib/saxon-9.1.0.8-dom.jar:/data/data/com.termux/files/home/LearnJava/lib/saxon-9.1.0.8.jar
+ declare -r mainClass=net.sourceforge.pmd.PMD
+ declare -r exclusionsFile=.exclusions
+ declare -r fileslist=pmdfiles.txt
+ declare -a exclusions
+ declare -i res=0
+ proj=Hello
+ '[' 1 -ne 1 ']'
+ '[' -d Hello ']'
+ readExclusions
+ '[' -e Hello/.exclusions ']'
+ set -o noglob
+ cd Hello
+ '[' -e pmdfiles.txt ']'
+ rm ./pmdfiles.txt
+ '[' -e setupclasspath ']'
+ find . -type f -regex '.*[.]\(java\|jsp\|xml\|pom\)$'
+ tr '\n' ,
+ '[' -s pmdfiles.txt ']'
+ java -cp /data/data/com.termux/files/home/LearnJava/lib/antlr4-runtime-4.7.2.jar:/data/data/com.termux/files/home/LearnJava/lib/asm-9.1.jar:/data/data/com.termux/files/home/LearnJava/lib/commons-io-2.6.jar:/data/data/com.termux/files/home/LearnJava/lib/commons-lang3-3.8.1.jar:/data/data/com.termux/files/home/LearnJava/lib/gson-2.8.5.jar:/data/data/com.termux/files/home/LearnJava/lib/jcommander-1.48.jar:/data/data/com.termux/files/home/LearnJava/lib/pmd-core-6.35.0.jar:/data/data/com.termux/files/home/LearnJava/lib/pmd-java-6.35.0.jar:/data/data/com.termux/files/home/LearnJava/lib/pmd-jsp-6.35.0.jar:/data/data/com.termux/files/home/LearnJava/lib/pmd-xml-6.35.0.jar:/data/data/com.termux/files/home/LearnJava/lib/saxon-9.1.0.8-dom.jar:/data/data/com.termux/files/home/LearnJava/lib/saxon-9.1.0.8.jar net.sourceforge.pmd.PMD -filelist pmdfiles.txt -R /data/data/com.termux/files/home/LearnJava/pmdrules.xml -f text -min 5 -norulesetcompatibility -failOnViolation true -cache pmd.cache -reportfile pmd.errors -auxclasspath :. -t 5
May 29, 2021 8:57:54 AM net.sourceforge.pmd.cache.FileAnalysisCache loadFromFile
INFO: Analysis cache loaded
May 29, 2021 8:58:02 AM net.sourceforge.pmd.PMD doPMD
SEVERE: Exception during processing
java.lang.NullPointerException
	at java.base/java.nio.file.Files.provider(Files.java:101)
	at java.base/java.nio.file.Files.createDirectory(Files.java:690)
	at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:797)
	at java.base/java.nio.file.Files.createDirectories(Files.java:743)
	at net.sourceforge.pmd.util.IOUtil.createWriter(IOUtil.java:80)
	at net.sourceforge.pmd.renderers.AbstractRenderer.setReportFile(AbstractRenderer.java:124)
	at net.sourceforge.pmd.PMD.doPMD(PMD.java:240)
	at net.sourceforge.pmd.PMD.runPmd(PMD.java:574)
	at net.sourceforge.pmd.PMD.runPmd(PMD.java:546)
	at net.sourceforge.pmd.PMD.main(PMD.java:502)

May 29, 2021 8:58:03 AM net.sourceforge.pmd.PMD doPMD
INFO: 
Mandatory arguments:
1) A java source code filename or directory
2) A report format 
3) A ruleset filename or a comma-delimited string of ruleset filenames

For example: 
C:\>pmd-bin-6.35.0\bin\pmd.bat -d c:\my\source\code -f html -R java-unusedcode

Languages and version suported:
java, jsp, pom, wsdl, xml, xsl

Available report formats and their configuration properties are:
   codeclimate: Code Climate integration.
   csv: Comma-separated values tabular format.
        problem - Include Problem column   default: true
        package - Include Package column   default: true
        file - Include File column   default: true
        priority - Include Priority column   default: true
        line - Include Line column   default: true
        desc - Include Description column   default: true
        ruleSet - Include Rule set column   default: true
        rule - Include Rule column   default: true
   emacs: GNU Emacs integration.
   empty: Empty, nothing.
   html: HTML format
        linePrefix - Prefix for line number anchor in the source file.
        linkPrefix - Path to HTML source.
        htmlExtension - Replace file extension with .html for the links (default: false)   default: false
   ideaj: IntelliJ IDEA integration.
        classAndMethodName - Class and Method name, pass '.method' when processing a directory.   default: 
        sourcePath - Source path.   default: 
        fileName - File name.   default: 
   json: JSON format.
   sarif: Static Analysis Results Interchange Format (SARIF)
   summaryhtml: Summary HTML format.
        linePrefix - Prefix for line number anchor in the source file.
        linkPrefix - Path to HTML source.
        htmlExtension - Replace file extension with .html for the links (default: false)   default: false
   text: Text format.
   textcolor: Text format, with color support (requires ANSI console support, e.g. xterm, rxvt, etc.).
        color - Enables colors with anything other than 'false' or '0'.   default: yes
   textpad: TextPad integration.
   vbhtml: Vladimir Bossicard HTML format.
   xml: XML format.
        encoding - XML encoding format, defaults to UTF-8.   default: UTF-8
   xslt: XML with a XSL Transformation applied.
        encoding - XML encoding format, defaults to UTF-8.   default: UTF-8
        xsltFilename - The XSLT file name.
   yahtml: Yet Another HTML format.
        outputDir - Output directory.

For example on windows: 
C:\>pmd-bin-6.35.0\bin\pmd.bat -dir c:\my\source\code -format text -R rulesets/java/quickstart.xml -version 1.5 -language java -debug
C:\>pmd-bin-6.35.0\bin\pmd.bat -dir c:\my\source\code -f xml -rulesets rulesets/java/quickstart.xml,category/java/codestyle.xml -encoding UTF-8
C:\>pmd-bin-6.35.0\bin\pmd.bat -d c:\my\source\code -rulesets rulesets/java/quickstart.xml -auxclasspath lib\commons-collections.jar;lib\derby.jar
C:\>pmd-bin-6.35.0\bin\pmd.bat -d c:\my\source\code -f html -R rulesets/java/quickstart.xml -auxclasspath file:///C:/my/classpathfile

For example on *nix: 
$ pmd-bin-6.35.0/bin/run.sh pmd -dir /home/workspace/src/main/java/code -f html -rulesets rulesets/java/quickstart.xml,category/java/codestyle.xml
$ pmd-bin-6.35.0/bin/run.sh pmd -d ./src/main/java/code -R rulesets/java/quickstart.xml -f xslt -property xsltFilename=my-own.xsl
$ pmd-bin-6.35.0/bin/run.sh pmd -d ./src/main/java/code -f html -R rulesets/java/quickstart.xml -auxclasspath commons-collections.jar:derby.jar




+ res=0
+ set +o noglob
+ exit 0



Running PMD through: CLI**

Using JDK 11.

Running PMD through Ant and Maven works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.was:duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions