summaryrefslogtreecommitdiffstats
path: root/models-base/src/main/java/org
diff options
context:
space:
mode:
authorRashmi Pujar <rashmi.pujar1@bell.ca>2022-02-23 23:40:54 -0500
committerRashmi Pujar <rashmi.pujar1@bell.ca>2022-02-24 10:50:46 -0500
commitf0ae42bb24bd4ee98f6b7b3acf2e47d96946de1b (patch)
treee01758a4d1fca5ff785ee21c73553de789208cd0 /models-base/src/main/java/org
parentc89f17af3cccff82d3f251e7fe73910ea8e26dbf (diff)
Fix for ClassCastException on PfConceptContainer get method usages
Typecasting Map to NavigableMap leads to ClassCastException. The usages of the get methods in delete policy, policyType endpoints in policy/api (using spring data jpa) cause the unchecked class-cast exception. Fix is to instead copy the Map entries into a newly created TreeMap instance. Issue-ID: POLICY-3924 Signed-off-by: Rashmi Pujar <rashmi.pujar1@bell.ca> Change-Id: I60625980d6f2692ffa7dd3bd9f53d10b43c13f4a
Diffstat (limited to 'models-base/src/main/java/org')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
index a98a7ac54..5f38a395a 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -331,30 +332,37 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
if (conceptKey.isNullVersion()) {
return get(conceptKey.getName());
} else {
- return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKey);
+ return new PfConceptGetterImpl<>(getNavigableConceptMap()).get(conceptKey);
}
}
@Override
public C get(final String conceptKeyName) {
- return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKeyName);
+ return new PfConceptGetterImpl<>(getNavigableConceptMap()).get(conceptKeyName);
}
@Override
public C get(final String conceptKeyName, final String conceptKeyVersion) {
- return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKeyName,
- conceptKeyVersion);
+ return new PfConceptGetterImpl<>(getNavigableConceptMap()).get(conceptKeyName, conceptKeyVersion);
}
@Override
public Set<C> getAll(final String conceptKeyName) {
- return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).getAll(conceptKeyName);
+ return new PfConceptGetterImpl<>(getNavigableConceptMap()).getAll(conceptKeyName);
}
@Override
public Set<C> getAll(final String conceptKeyName, final String conceptKeyVersion) {
- return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).getAll(conceptKeyName,
- conceptKeyVersion);
+ return new PfConceptGetterImpl<>(getNavigableConceptMap()).getAll(conceptKeyName, conceptKeyVersion);
+ }
+
+ /**
+ * Get the concept map as a NavigableMap object.
+ *
+ * @return NavigableMap conceptMap instance.
+ */
+ private NavigableMap<PfConceptKey, C> getNavigableConceptMap() {
+ return new TreeMap<>(conceptMap);
}
/**
@@ -386,4 +394,4 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
+ keyFieldValue + " does not match the value " + conceptField + " in the concept field");
}
}
-}
+} \ No newline at end of file