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] PMD/CPD produces invalid XML (insufficient escaping/wrong encoding) · Issue #2615 · pmd/pmd

[core] PMD/CPD produces invalid XML (insufficient escaping/wrong encoding) #2615

New issue
Copy link
New issue
Copy link
Closed
#2633
Closed
[core] PMD/CPD produces invalid XML (insufficient escaping/wrong encoding)#2615
#2633
Copy link
Assignees
adangel
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
6.26.0

Description

@maikelsteneker
maikelsteneker
opened on Jun 26, 2020
Issue body actions

Affects PMD Version: PMD 6.24.0

Description:

When running on a file with a different encoding than the system default, PMD can produce invalid XML.

Steps to reproduce:

Please provide detailed steps for how we can reproduce the bug.

  1. Use the following UTF-8 encoded source file: MyClass.java.zip
  2. Invoke PMD on Windows 10 as follows: pmd -d C:/tmp/MyClass.java -rulesets category/java/errorprone.xml/AvoidDuplicateLiterals -format xml -language java > out.xml
    This produces the following XML output: out.xml.zip
    The encoding of this file should be UTF-8 (as indicated at the start of the file), but contains files in a different encoding. Running xmllint on it produces:
    /tmp/out.xml:8: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xE9 0xE9 0xE9 0xE9 The String literal "��������" appears 5 times in this file; the first ^

In fact, in my case, these characters are in the Windows-1255 encoding. I think PMD uses this encoding because it uses the system property file.encoding. One workaround is to use the same encoding as the file (UTF-8 by default).

Running PMD through: [CLI]

Activity

  1. maikelsteneker
    added
    a:bugPMD crashes or fails to analyse a file.
    on Jun 26, 2020
  2. maikelsteneker commented on Jun 26, 2020

    @maikelsteneker
    maikelsteneker
    on Jun 26, 2020
    ContributorAuthor
    More actions

    The same can happen with CPD when it includes code in its <codefragment> blocks. I've also seen it include form feed characters (^L in vim), which aren't valid in XML 1.0.

  3. SulisNyx commented on Jun 30, 2020

    @SulisNyx
    SulisNyx
    on Jun 30, 2020
    More actions

    I have seen invalid xml in the code fragment section many times. I've included an example output for pypy-5.4.0.
    pypy-cpd.xml.zip

    The xmllint errors:
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38108: parser error : CData section not finished
    import unittest
    from test.test_support import run_

    ^
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38108: parser error : PCDATA invalid Char value 12

    ^
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38129: parser error : StartTag: invalid element name
    ('\x1b$B%O%m!<%o!<%k%I!\x1b(B', 'iso-2022-jp'),
    ^
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38129: parser error : StartTag: invalid element name
    ('\x1b$B%O%m!<%o!<%k%I!
    \x1b(B', 'iso-2022-jp'),
    ^
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38151: parser error : PCDATA invalid Char value 12

    ^
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38162: parser error : PCDATA invalid Char value 12

    ^
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38164: parser error : Sequence ']]>' not allowed in content

    ^
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38164: parser error : Sequence ']]>' not allowed in content
    unittest.main(defaultTest='suite')]]>
    ^
    vaults/cpd_test/projects/vault-sample/systems/pypy-5.4.0/data/cpd_results/cpd-python.xml:38164: parser error : internal error: detected an error in element content

    unittest.main(defaultTest='suite')]]></codefragment>
    
  4. maikelsteneker commented on Jun 30, 2020

    @maikelsteneker
    maikelsteneker
    on Jun 30, 2020
    ContributorAuthor
    More actions

    @SulisNyx: thanks. This is a good example of a file with a couple of those form feed characters that are invalid in XML. After removing those, valid XML remains.

  5. adangel
    changed the title [-][core] PMD produces invalid XML[/-] [+][core] PMD/CPD produces invalid XML (unsufficient escaping)[/+] on Jul 2, 2020
  6. adangel
    changed the title [-][core] PMD/CPD produces invalid XML (unsufficient escaping)[/-] [+][core] PMD/CPD produces invalid XML (unsufficient escaping/wrong encoding)[/+] on Jul 2, 2020
  7. adangel
    changed the title [-][core] PMD/CPD produces invalid XML (unsufficient escaping/wrong encoding)[/-] [+][core] PMD/CPD produces invalid XML (insufficient escaping/wrong encoding)[/+] on Jul 3, 2020
  8. adangel
    self-assigned this
    on Jul 3, 2020
  9. adangel
    added this to the 6.26.0 milestone on Jul 3, 2020
  10. adangel
    added a commit that references this issue on Jul 5, 2020

    [doc] Update release notes, fixes pmd#2615

    This issue will close once commit 60f905b is merged into the 'main' branch.
    60f905b
  11. oowekyala
    closed this as completedin 60f905bon Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @adangel
    adangel

Labels

a:bugPMD crashes or fails to analyse a file.

Type

No type

Projects

No projects

    Milestone

    • 6.26.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.