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:
- 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))
- 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.
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:
Exception Stacktrace:
Steps to reproduce:
a.cpp,b.cpp) with UTF-8 with BOM. (The file size will be 5 bytes; 3(BOM) + 1(semicolon) + 1(newline))pmd cpd --verbose --minimum-tokens=1 --language=cpp --encoding=UTF-8 --dir=a.cpp --dir=b.cppKnown workarounds: