Affects PMD Version:
This bug is only reproducible starting with release 7.1.0+. It does not reproduce with 7.0.0.
Make sure, to test with the latest PMD version.
Description:
We are finding that the Copy Paste Detector no longer works on even medium size projects without reporting out of memory errors.
For example, try to clone and scan the dev branch of https://github.com/forcedotcom/sfdx-scanner.
Exception Stacktrace:
Error (1): Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.HashMap.resize(HashMap.java:700)
at java.base/java.util.HashMap.putVal(HashMap.java:625)
at java.base/java.util.HashMap.put(HashMap.java:608)
at java.base/java.util.HashSet.add(HashSet.java:220)
at net.sourceforge.pmd.cpd.MatchCollector.registerTokenMatch(MatchCollector.java:119)
at net.sourceforge.pmd.cpd.MatchCollector.reportMatch(MatchCollector.java:115)
at net.sourceforge.pmd.cpd.MatchCollector.collect(MatchCollector.java:57)
at net.sourceforge.pmd.cpd.MatchAlgorithm.lambda$findMatches$1(MatchAlgorithm.java:57)
at net.sourceforge.pmd.cpd.MatchAlgorithm$$Lambda$139/0x000000080017b440.accept(Unknown Source)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1693)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
at net.sourceforge.pmd.cpd.MatchAlgorithm.findMatches(MatchAlgorithm.java:53)
at net.sourceforge.pmd.cpd.CpdAnalysis.performAnalysis(CpdAnalysis.java:191)
at net.sourceforge.pmd.cli.commands.internal.CpdCommand.doExecute(CpdCommand.java:134)
at net.sourceforge.pmd.cli.commands.internal.CpdCommand.doExecute(CpdCommand.java:29)
at net.sourceforge.pmd.cli.commands.internal.AbstractAnalysisPmdSubcommand$$Lambda$77/0x0000000800147c40.apply(Unknown Source)
at net.sourceforge.pmd.cli.internal.PmdRootLogger.executeInLoggingContext(PmdRootLogger.java:55)
at net.sourceforge.pmd.cli.commands.internal.AbstractAnalysisPmdSubcommand.execute(AbstractAnalysisPmdSubcommand.java:111)
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:2041)
at picocli.CommandLine.access$1500(CommandLine.java:148)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
curl -OL https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.2.0/pmd-dist-7.2.0-bin.zip
unzip pmd-dist-7.2.0-bin.zip
alias pmd="./pmd-bin-7.2.0/bin/pmd"
git clone https://github.com/forcedotcom/sfdx-scanner.git sfdx-scanner
java -cp "pmd-bin-7.2.0/lib/*" -Xmx1024m net.sourceforge.pmd.cli.PmdCli cpd --minimum-tokens 100 --dir sfdx-scanner --format xml --language java --skip-lexical-errors
Note that a full gig of heap space should be enough. It always has been. But now it seems we need to increase it to like -Xmx2048m
to get things to work again.
Something obviously changed between v 7.0.0 and 7.1.0 to cause more memory to be consumed.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
JAVA
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4