GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Fix XMLRenderer newlines when running under IBM Java by adangel · Pull Request #2831 · pmd/pmd

Conversation

@adangel

@adangel adangel commented Oct 15, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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

  • [core] Fix XMLRenderer encoding issues #2633
  • [core] PMD/CPD produces invalid XML (insufficient escaping/wrong encoding) #2615
  • See also https://stackoverflow.com/questions/29675481/xmlstreamwriter-java-8-writecharacters-xd

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adangel
[core] Fix XMLRenderer newlines when running under IBM Java
d8616cc
@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
@adangel
[skip ci] [doc] Update release notes, refs pmd#2831
b22bc05
@ghost

ghost commented Oct 15, 2020 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jsotuyod
jsotuyod reviewed Oct 15, 2020
View reviewed changes
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel @jsotuyod
[core] XMLRenderer - remove unecessary initialization
61acc52
Co-authored-by: Juan Martín Sotuyo Dodero <[email protected]>
@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
[core] Fix XMLRenderer with UTF-16 #2874
Merged
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jsotuyod jsotuyod jsotuyod left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

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

Projects

None yet

Milestone

6.29.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@adangel @jsotuyod
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.