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 — [cli] All files are analyzed despite parameter `--file-list` · Issue #3999 · pmd/pmd

[cli] All files are analyzed despite parameter --file-list #3999

New issue
Copy link
New issue
Copy link
Closed
#4000
Closed
[cli] All files are analyzed despite parameter --file-list#3999
#4000
Copy link
Assignees
adangel
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
6.47.0

Description

@adangel
adangel
opened on Jun 2, 2022
Issue body actions

Affects PMD Version: 6.46.0

Description:

With the latest version, the cli parameter --file-list seems to be ignored. See original bug report pmd/pmd-github-action#97

I suspect that the change #3960 introduced this regression, but not sure yet how exactly.
It could also be #3968, since we use IOUtil.toString to read the file.

While looking at the code and the new documentation, I noticed a discrepancy:
The Github Action creates a fileslist with a single line and the file names are joined with a comma. The new cli doc says, the filelist should contain one filename per line. This probably should be changed in a future version of the GitHub Action

See also the test run: https://github.com/pmd/pmd-github-action-tests/runs/6713644618?check_suite_focus=true

##[debug]Push on refs/heads/java: 87f683bdbbb5b9adef1d4a5a6dd4fd001d679b52...7bf9dc16fb014d123631a977c1f0b4bb40b99caa
##[debug] got 6 entries from page 1 to check...
##[debug]   0: added src/main/java2/AbstractClassWithoutAnyMethodSample.java
##[debug]   1: added src/main/java2/AllInOne.java
##[debug]   2: added src/main/java2/AvoidCatchingThrowableSample.java
##[debug]   3: added src/main/java2/ReturnFromFinallyBlockSample.java
##[debug]   4: added src/main/java2/UnconditionalIfStatementSample.java
##[debug]   5: added src/main/java2/UseCollectionIsEmptySample.java
##[debug]   after filtering by status and with '.' 6 files remain:
##[debug]   src/main/java2/AbstractClassWithoutAnyMethodSample.java, src/main/java2/AllInOne.java, src/main/java2/AvoidCatchingThrowableSample.java, src/main/java2/ReturnFromFinallyBlockSample.java, src/main/java2/UnconditionalIfStatementSample.java, src/main/java2/UseCollectionIsEmptySample.java
Running PMD 6.46.0 on 6 modified files...
/opt/hostedtoolcache/pmd/6.46.0/x64/pmd-bin-6.46.0/bin/run.sh pmd --no-cache --file-list pmd.filelist -f sarif -R ruleset.xml,category/java/design.xml/AbstractClassWithoutAnyMethod -r pmd-report.sarif

Only the files under src/main/java2 are in the filelist pmd.filelist. But PMD also reports violations for files under src/main/java.

Running PMD through: CLI

Activity

  1. adangel
    added
    a:bugPMD crashes or fails to analyse a file.
    on Jun 2, 2022
  2. adangel
    added this to the 6.47.0 milestone on Jun 2, 2022
  3. adangel commented on Jun 2, 2022

    @adangel
    adangel
    on Jun 2, 2022
    MemberAuthor
    More actions

    I think here's the problematic code(path):

    pmd/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java

    Line 227 in 973eaef

    configuration.setInputPaths(this.getSourceDir());

    From jcommander, we get an empty list for the --dir parameter. PMDParameters.getSourceDir() returns for this empty list an empty string. PMDConfiguration.setInputPaths() splits this string at commas and adds it to the list of inputPaths. We end up with a List, which contains an empty string.
    When collecting the files to analyze, we relative this empty string against the current working directory and so scan all the files in the current dir.

    Simple fix would be to check for empty string in PMDConfiguration.setInputPaths() to avoid adding a empty string to the list.

  4. adangel
    self-assigned this
    on Jun 2, 2022
  5. adangel
    changed the title [-][cli] Parameter `--file-list` is ignored[/-] [+][cli] All files are analyzed despite parameter `--file-list`[/+] on Jun 4, 2022
  6. adangel commented on Jun 4, 2022

    @adangel
    adangel
    on Jun 4, 2022
    MemberAuthor
    More actions

    The fix is even simpler - the above mentioned line should be

    configuration.setInputPaths(this.getInputPaths()); 

    Then the conversion of the List to and from a comma separated string value is avoided.
    Will push a PR soon.

  7. adangel commented on Jun 4, 2022

    @adangel
    adangel
    on Jun 4, 2022
    MemberAuthor
    More actions

    There is a workaround for this issue, if you can control the cli parameters yourself. You'll need to specify additionally the parameter --dir with either a non-existing directory or just an empty directory. Then only the files provided in the file list are analyzed, since there are no additional files to search for.

    Since there is a workaround, it's not worth to fix this in a patch release and the next minor 6.47.0 will do.

  8. adangel
    added a commit that references this issue on Jun 4, 2022

    [core] Fix cli when only --file-list is used

    This issue will close once commit 1e99280 is merged into the 'main' branch.
    1e99280
  9. adangel
    closed this as completedin 1e99280on Jun 13, 2022
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.47.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.