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 — [cpd] AnyTokenizer doesn't count columns correctly · Issue #2760 · pmd/pmd

[cpd] AnyTokenizer doesn't count columns correctly #2760

New issue
Copy link
New issue
Copy link
Closed
#2758
Closed
[cpd] AnyTokenizer doesn't count columns correctly#2760
#2758
Copy link
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
6.28.0

Description

@adangel
adangel
opened on Sep 2, 2020
Issue body actions

Affects PMD Version: 6.25.0+

Description:

With 6.25.0 AnyTokenizer now supports columns (b976d65), but the columns are not reset when a new line starts. So the beginColumn/endColumn property is always incrementing...

Code Sample demonstrating the issue:

Create two files file1.txtand file2.txt with the following content:

file1.txt

file one:
This is some
duplication.
Some other content.

file2.txt

file2
This is some
    duplication.
Something different.

Steps to reproduce:

  1. run.sh cpd --language any --minimum-tokens 4 --format xml --files file1.txt file2.txt

The output is this:

<?xml version="1.0" encoding="UTF-8"?>
<pmd-cpd>
   <duplication lines="2" tokens="4">
      <file column="10" endcolumn="33" endline="3" line="2"
            path="/.../file1.txt"/>
      <file column="6" endcolumn="33" endline="3" line="2"
            path="/.../file2.txt"/>
      <codefragment><![CDATA[This is some
duplication.]]></codefragment>
   </duplication>
</pmd-cpd>

The begin column should be for both occurrences "1", the endcolumn in file 1 should be 12 and in file 2 it should be 16.

Running PMD through: CLI

I guess, we simply need to reset the var colNumber at

pmd/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java

Line 39 in 3ce68f4

lineNumber++;

Maybe we can also leverage the new tokenizer test method ("CpdTextComparisonTest") for the AnyTokenizer.

Relates to #2758

Activity

  1. adangel
    added
    a:bugPMD crashes or fails to analyse a file.
    on Sep 2, 2020
  2. oowekyala commented on Sep 3, 2020

    @oowekyala
    oowekyala
    on Sep 3, 2020
    Member
    More actions

    Maybe we can also leverage the new tokenizer test method ("CpdTextComparisonTest") for the AnyTokenizer.

    This would be nice but in this case we would have to write those tests outside pmd-core, and I'm not sure where. With #2758, at least we test it for three modules

  3. adangel
    changed the title [-][core][cpd] AnyTokenizer doesn't count columns correctly[/-] [+][cpd] AnyTokenizer doesn't count columns correctly[/+] on Sep 12, 2020
  4. adangel
    added this to the 6.28.0 milestone on Sep 12, 2020
  5. adangel
    added a commit that references this issue on Sep 12, 2020

    [core] AnyTokenizer: Add testcase to verify #2760 is fixed

    5192fdc
  6. adangel
    closed this as completedin d261f44on Sep 12, 2020
  7. adangel
    closed this as completedin #2758on Sep 12, 2020
  8. adangel
    modified the milestone: 6.28.0 on Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.28.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.