Describe the PR
When running PMD under Windows with IBM's Java, then the produced XML report looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd" version="6.28.0" timestamp="2020-10-15T10:24:55.318">
</pmd>
IBM's Java obviously uses an interesting implementation for XMLStreamWriter. The produced XML is invalid, e.g. xmllint says this:
$ xmllint out.xml
out.xml:1: parser error : Start tag expected, '<' not found
<?xml version="1.0" encoding="UTF-8"?>
This problem exists since I've refactored XMLRenderer to use XMLStreamWriter with PMD 6.26.0 (see #2633).
Testing is a bit complicated, but possible under Linux (originally, this problem appears only under Windows, due to different default line separators). In order to test it, you'll need
- IBM's Java 8 SDK -> https://www.ibm.com/support/pages/java-sdk-downloads-version-80
- The following start script for PMD for some bash magic...
#!/bin/bash
PMD_DIR=~/PMD/pmd-bin-6.28.0
#PMD_DIR=~/PMD/pmd-bin-6.29.0-SNAPSHOT
PMD_JAVA_OPTS=-Dline.separator=$'\r\n'
LIB_DIR=$PMD_DIR/lib
# need to source run.sh, otherwise subshell is used and IFS is not inherited and contains $'\n'
# which will destroy line.separator property (PMD_JAVA_OPTS is word split at the newline char)
IFS=' '
source $PMD_DIR/bin/run.sh pmd -f xml -d . -R rulesets/java/quickstart.xml -no-cache
Other changes
This PR also adds the missing call to "writeEndDocument()".
Related issues
Ready?
- Added unit tests for fixed bug/feature
- Passing all unit tests
- Complete build
./mvnw clean verify passes (checked automatically by travis)
- Added (in-code) documentation (if needed)