Skip to content

[core] Fix XMLRenderer newlines when running under IBM Java#2831

Merged
adangel merged 3 commits into
pmd:masterfrom
adangel:xml-renderer-ibm-java
Oct 22, 2020
Merged

[core] Fix XMLRenderer newlines when running under IBM Java#2831
adangel merged 3 commits into
pmd:masterfrom
adangel:xml-renderer-ibm-java

Conversation

@adangel

@adangel adangel commented Oct 15, 2020

Copy link
Copy Markdown
Member

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"?>&#xD;
<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">&#xD;
</pmd>&#xD;

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"?>&#xD;

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

  1. IBM's Java 8 SDK -> https://www.ibm.com/support/pages/java-sdk-downloads-version-80
  2. 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)

@adangel adangel added the a:bug PMD crashes or fails to analyse a file. label Oct 15, 2020
@adangel adangel added this to the 6.29.0 milestone Oct 15, 2020
@ghost

ghost commented Oct 15, 2020

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

Comment thread pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java Outdated
Co-authored-by: Juan Martín Sotuyo Dodero <juansotuyo@gmail.com>
@adangel adangel self-assigned this Oct 22, 2020
@adangel adangel merged commit 14d1f7a into pmd:master Oct 22, 2020
@adangel adangel deleted the xml-renderer-ibm-java branch October 22, 2020 07:59
@adangel adangel mentioned this pull request Oct 26, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:bug PMD crashes or fails to analyse a file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants