aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java/org
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-10-02 21:31:04 +0100
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-10-03 21:04:09 +0100
commit153aa48c6945cfc54ceb1b3f6a38508ad93f1d16 (patch)
tree9b4510292b2efd1e11d34f4493d7604ea98d2172 /cps-service/src/main/java/org
parent2686ec95a09bafa2846860d403516f89cb2ed0c0 (diff)
[BUG] Fix memory leak related to using arrays in Hibernate
The use of arrays like String[] instead of Collection<String> in JpaRepository methods is causing a memory leak, most likely due to a bug in the hypersistence-utils dependency which provides the feature. Note code using arrays in JDBC (via jdbcTemplate) is not affected. This patch removes most uses of arrays in Java, except one needed for FragmentPrefetchRepository using JDBC setArray(), which is safe. Issue-ID: CPS-2430 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I94f8c3d4c8c32ebe0978c08d3226a196a95bf3b9
Diffstat (limited to 'cps-service/src/main/java/org')
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java22
1 files changed, 10 insertions, 12 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java b/cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java
index 597164598a..a5865be657 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/YangParserHelper.java
@@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLInputFactory;
@@ -181,12 +182,12 @@ public class YangParserHelper {
private static Map<String, Object> getDataSchemaNodeAndIdentifiersByXpath(final String parentNodeXpath,
final SchemaContext schemaContext) {
- final String[] xpathNodeIdSequence = xpathToNodeIdSequence(parentNodeXpath);
+ final List<String> xpathNodeIdSequence = xpathToNodeIdSequence(parentNodeXpath);
return findDataSchemaNodeAndIdentifiersByXpathNodeIdSequence(xpathNodeIdSequence, schemaContext.getChildNodes(),
new ArrayList<>());
}
- private static String[] xpathToNodeIdSequence(final String xpath) {
+ private static List<String> xpathToNodeIdSequence(final String xpath) {
try {
return CpsPathUtil.getXpathNodeIdSequence(xpath);
} catch (final PathParsingException pathParsingException) {
@@ -196,17 +197,16 @@ public class YangParserHelper {
}
private static Map<String, Object> findDataSchemaNodeAndIdentifiersByXpathNodeIdSequence(
- final String[] xpathNodeIdSequence,
+ final List<String> xpathNodeIdSequence,
final Collection<? extends DataSchemaNode> dataSchemaNodes,
final Collection<QName> dataSchemaNodeIdentifiers) {
- final String currentXpathNodeId = xpathNodeIdSequence[0];
+ final String currentXpathNodeId = xpathNodeIdSequence.get(0);
final DataSchemaNode currentDataSchemaNode = dataSchemaNodes.stream()
.filter(dataSchemaNode -> currentXpathNodeId.equals(dataSchemaNode.getQName().getLocalName()))
.findFirst().orElseThrow(() -> schemaNodeNotFoundException(currentXpathNodeId));
dataSchemaNodeIdentifiers.add(currentDataSchemaNode.getQName());
- if (xpathNodeIdSequence.length <= 1) {
- final Map<String, Object> dataSchemaNodeAndIdentifiers =
- new HashMap<>();
+ if (xpathNodeIdSequence.size() <= 1) {
+ final Map<String, Object> dataSchemaNodeAndIdentifiers = new HashMap<>();
dataSchemaNodeAndIdentifiers.put("dataSchemaNode", currentDataSchemaNode);
dataSchemaNodeAndIdentifiers.put("dataSchemaNodeIdentifiers", dataSchemaNodeIdentifiers);
return dataSchemaNodeAndIdentifiers;
@@ -217,13 +217,11 @@ public class YangParserHelper {
((DataNodeContainer) currentDataSchemaNode).getChildNodes(),
dataSchemaNodeIdentifiers);
}
- throw schemaNodeNotFoundException(xpathNodeIdSequence[1]);
+ throw schemaNodeNotFoundException(xpathNodeIdSequence.get(1));
}
- private static String[] getNextLevelXpathNodeIdSequence(final String[] xpathNodeIdSequence) {
- final String[] nextXpathNodeIdSequence = new String[xpathNodeIdSequence.length - 1];
- System.arraycopy(xpathNodeIdSequence, 1, nextXpathNodeIdSequence, 0, nextXpathNodeIdSequence.length);
- return nextXpathNodeIdSequence;
+ private static List<String> getNextLevelXpathNodeIdSequence(final List<String> xpathNodeIdSequence) {
+ return xpathNodeIdSequence.subList(1, xpathNodeIdSequence.size());
}
private static DataValidationException schemaNodeNotFoundException(final String schemaNodeIdentifier) {