Skip to content

[scala] CPD terminates with an exception when a small value is set for --minimum-tokens #2153

Closed

Description

@yasuharu-sato

Affects PMD Version:
6.18.0, 6.20.0

Rule:

Description:
When targeting a scala file, if a small value is set for --minimum-tokens, CPD will exit with an exception.

Code Sample demonstrating the issue:

object Foo {
    void foo() {
        String[] array = null;
        array = {"abc", "def", "ghi"};
    }
}

I prepared another same file.

Running PMD through: [CLI]

pmd-bin-6.18.0/bin/run.sh cpd --minimum-tokens 20 --language scala --files scala/

Activity

  1. jsotuyod commented on Dec 9, 2019

    @jsotuyod
    Member

    @yasuharu-sato thanks for the report. Would you please submit the exception stacktrace you are seeing?

  2. yasuharu-sato commented on Dec 10, 2019

    @yasuharu-sato
    Author

    Sure

    java.lang.IndexOutOfBoundsException: fromIndex = -1
    	at java.base/java.util.AbstractList.subListRangeCheck(AbstractList.java:505)
    	at java.base/java.util.ArrayList.subList(ArrayList.java:1137)
    	at net.sourceforge.pmd.cpd.SourceCode$CodeLoader.getCodeSlice(SourceCode.java:45)
    	at net.sourceforge.pmd.cpd.SourceCode.getSlice(SourceCode.java:198)
    	at net.sourceforge.pmd.cpd.Mark.getSourceCodeSlice(Mark.java:41)
    	at net.sourceforge.pmd.cpd.Match.getSourceCodeSlice(Match.java:77)
    	at net.sourceforge.pmd.cpd.XMLRenderer.addCodeSnippet(XMLRenderer.java:129)
    	at net.sourceforge.pmd.cpd.XMLRenderer.render(XMLRenderer.java:109)
    	at net.sourceforge.pmd.cpd.CPDCommandLineInterface.main(CPDCommandLineInterface.java:94)
    	at net.sourceforge.pmd.cpd.CPD.main(CPD.java:177)
    
  3. added
    a:bug
    on May 15, 2020
  4. added
    needs:pmd7-revalidation
    on Apr 3, 2024
  5. changed the title [-][scala]CPD terminates with an exception when a small value is set for --minimum-tokens.[/-] [+][scala] CPD terminates with an exception when a small value is set for --minimum-tokens[/+] on Sep 18, 2026
  6. added this to the 7.0.0 milestone on Sep 18, 2026
  7. removed
    needs:pmd7-revalidation
    on Sep 18, 2026
  8. modified the milestones: 7.0.0, 6.25.0 on Sep 26, 2026
  9. added a commit that references this issue on Sep 26, 2026
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:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions