From 10bfa395e547e18e1fae47a88d731a34fdf5a5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 27 Jun 2024 20:29:15 -0300 Subject: [PATCH 1/2] Explicitely use no-arg constructor - Inadvertly I was using the constructor that received an int as initial capacity, which instantiated massive collections leading to an increase in memory usage. --- .../main/java/net/sourceforge/pmd/cpd/MatchCollector.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java index 36c6e99c2f..d2d4264f2b 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java @@ -68,7 +68,7 @@ class MatchCollector { * - BC * It should be reduced to a single match with 3 marks */ - if (tokenMatchSets.computeIfAbsent(mark1.getIndex(), HashSet::new).contains(mark2.getIndex())) { + if (tokenMatchSets.computeIfAbsent(mark1.getIndex(), (i) -> new HashSet<>()).contains(mark2.getIndex())) { return; } @@ -76,7 +76,7 @@ class MatchCollector { // always rely on the lowest mark index, as that's the order in which process them final int lowestKey = tokenMatchSets.get(mark1.getIndex()).stream().reduce(mark1.getIndex(), Math::min); - List matches = matchTree.computeIfAbsent(lowestKey, ArrayList::new); + List matches = matchTree.computeIfAbsent(lowestKey, (i) -> new ArrayList<>()); Iterator matchIterator = matches.iterator(); while (matchIterator.hasNext()) { Match m = matchIterator.next(); @@ -116,8 +116,8 @@ class MatchCollector { } private void registerTokenMatch(TokenEntry mark1, TokenEntry mark2) { - tokenMatchSets.computeIfAbsent(mark1.getIndex(), HashSet::new).add(mark2.getIndex()); - tokenMatchSets.computeIfAbsent(mark2.getIndex(), HashSet::new).add(mark1.getIndex()); + tokenMatchSets.computeIfAbsent(mark1.getIndex(), (i) -> new HashSet<>()).add(mark2.getIndex()); + tokenMatchSets.computeIfAbsent(mark2.getIndex(), (i) -> new HashSet<>()).add(mark1.getIndex()); } List getMatches() { From a9d43d0ad01702ade51c9f88b7ca86321c6fdafb Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 28 Jun 2024 08:27:34 +0200 Subject: [PATCH 2/2] [doc] Update release notes (#5090, #5066) --- docs/pages/release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 3efe00d5c4..0ec2a2936a 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -40,6 +40,7 @@ See also [Maven PMD Plugin]({{ baseurl }}pmd_userdocs_tools_maven.html). * [#2827](https://github.com/pmd/pmd/issues/2827): \[cli] Consider processing errors in exit status * core * [#4992](https://github.com/pmd/pmd/pull/4992): \[core] CPD: Include processing errors in XML report + * [#5066](https://github.com/pmd/pmd/issues/5066): \[core] CPD throws java.lang.OutOfMemoryError: Java heap space (since 7.1.0) * apex * [#4922](https://github.com/pmd/pmd/issues/4922): \[apex] SOQL syntax error with TYPEOF in sub-query * [#5053](https://github.com/pmd/pmd/issues/5053): \[apex] CPD fails to parse string literals with escaped characters