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 — [cpp] CPD: IndexOutOfBoundsException when a duplication is at end of file with UTF8-BOM · Issue #6641 · pmd/pmd

[cpp] CPD: IndexOutOfBoundsException when a duplication is at end of file with UTF8-BOM #6641

New issue
Copy link
New issue
Copy link
Closed
#6703
Closed
[cpp] CPD: IndexOutOfBoundsException when a duplication is at end of file with UTF8-BOM#6641
#6703
Copy link
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
7.26.0

Description

@k-satoda
k-satoda
opened on May 5, 2026
Issue body actions

Affects PMD Version:

PMD 7.24.0

Description:

When CPD finds a duplication at end of file with UTF8-BOM, CPD fails with error like following:

[ERROR] Exception while running CPD.: Invalid range [0, 3[ (length 3) in string of length 2

Exception Stacktrace:

[DEBUG] java.lang.IndexOutOfBoundsException: Invalid range [0, 3[ (length 3) in string of length 2
	at net.sourceforge.pmd.lang.document.Chars.validateRange(Chars.java:533)
	at net.sourceforge.pmd.lang.document.Chars.slice(Chars.java:493)
	at net.sourceforge.pmd.lang.document.Chars.subSequence(Chars.java:457)
	at net.sourceforge.pmd.lang.document.RootTextDocument.sliceOriginalText(RootTextDocument.java:121)
	at net.sourceforge.pmd.cpd.SourceManager.getSlice(SourceManager.java:90)
	at net.sourceforge.pmd.cpd.CPDReport.getSourceCodeSlice(CPDReport.java:61)
	at net.sourceforge.pmd.cpd.SimpleRenderer.renderOn(SimpleRenderer.java:67)
	at net.sourceforge.pmd.cpd.SimpleRenderer.render(SimpleRenderer.java:41)
	at net.sourceforge.pmd.cpd.CpdAnalysis.performAnalysis(CpdAnalysis.java:176)
	at net.sourceforge.pmd.cli.commands.internal.CpdCommand.doExecute(CpdCommand.java:136)
	at net.sourceforge.pmd.cli.commands.internal.CpdCommand.doExecute(CpdCommand.java:27)
	at net.sourceforge.pmd.cli.internal.PmdRootLogger.executeInLoggingContext(PmdRootLogger.java:55)
	at net.sourceforge.pmd.cli.commands.internal.AbstractAnalysisPmdSubcommand.execute(AbstractAnalysisPmdSubcommand.java:188)
	at net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand.call(AbstractPmdSubcommand.java:30)
	at net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand.call(AbstractPmdSubcommand.java:16)
	at picocli.CommandLine.executeUserObject(CommandLine.java:2031)
	at picocli.CommandLine.access$1500(CommandLine.java:148)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2469)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2461)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2423)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2277)
	at picocli.CommandLine$RunLast.execute(CommandLine.java:2425)
	at picocli.CommandLine.execute(CommandLine.java:2174)
	at net.sourceforge.pmd.cli.PmdCli.mainWithoutExit(PmdCli.java:25)
	at net.sourceforge.pmd.cli.PmdCli.main(PmdCli.java:29)

Steps to reproduce:

  1. Save this into two files (a.cpp, b.cpp) with UTF-8 with BOM. (The file size will be 5 bytes; 3(BOM) + 1(semicolon) + 1(newline))
;
  1. Run pmd cpd --verbose --minimum-tokens=1 --language=cpp --encoding=UTF-8 --dir=a.cpp --dir=b.cpp

Known workarounds:

  • Add some comments at the end of file.
  • Remove BOM if possible.

Activity

  1. k-satoda
    added
    a:bugPMD crashes or fails to analyse a file.
    on May 5, 2026
  2. UncleOwen commented on May 5, 2026

    @UncleOwen
    UncleOwen
    on May 5, 2026
    Member
    More actions

    Can confirm.

    In case anyone wants to work on this, here is a command line to create the input files:

    echo 77u/Owo= | base64 -d | tee a.cpp b.cpp
  3. lukasgraef
    added this to the 7.26.0 milestone on Jun 5, 2026
  4. lukasgraef
    closed this as completedin #6703on Jun 5, 2026
  5. lukasgraef
    added 3 commits that reference this issue on Jun 5, 2026

    [cpp] Fix #6641: CPD: IndexOutOfBoundsException when a duplication is…

    This issue will close once commit 419ebaa is merged into the 'main' branch.
    419ebaa

    [chore] #6641: Remove comment from test-data to reproduce original issue

    This issue will close once commit b9f50fa is merged into the 'main' branch.
    b9f50fa

    [chore] #6641: Remove comment from test-data to reproduce original is…

    This issue will close once commit 09ecf27 is merged into the 'main' branch.
    09ecf27
  6. adangel
    added a commit that references this issue on Jun 12, 2026

    [chore] #6641: Further improve the test (#6777)

    3fdaacc
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

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