From f0ae42bb24bd4ee98f6b7b3acf2e47d96946de1b Mon Sep 17 00:00:00 2001 From: Rashmi Pujar Date: Wed, 23 Feb 2022 23:40:54 -0500 Subject: 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 Change-Id: I60625980d6f2692ffa7dd3bd9f53d10b43c13f4a --- .../policy/models/base/PfConceptContainer.java | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'models-base/src/main/java') 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 ex if (conceptKey.isNullVersion()) { return get(conceptKey.getName()); } else { - return new PfConceptGetterImpl<>((NavigableMap) conceptMap).get(conceptKey); + return new PfConceptGetterImpl<>(getNavigableConceptMap()).get(conceptKey); } } @Override public C get(final String conceptKeyName) { - return new PfConceptGetterImpl<>((NavigableMap) conceptMap).get(conceptKeyName); + return new PfConceptGetterImpl<>(getNavigableConceptMap()).get(conceptKeyName); } @Override public C get(final String conceptKeyName, final String conceptKeyVersion) { - return new PfConceptGetterImpl<>((NavigableMap) conceptMap).get(conceptKeyName, - conceptKeyVersion); + return new PfConceptGetterImpl<>(getNavigableConceptMap()).get(conceptKeyName, conceptKeyVersion); } @Override public Set getAll(final String conceptKeyName) { - return new PfConceptGetterImpl<>((NavigableMap) conceptMap).getAll(conceptKeyName); + return new PfConceptGetterImpl<>(getNavigableConceptMap()).getAll(conceptKeyName); } @Override public Set getAll(final String conceptKeyName, final String conceptKeyVersion) { - return new PfConceptGetterImpl<>((NavigableMap) 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 getNavigableConceptMap() { + return new TreeMap<>(conceptMap); } /** @@ -386,4 +394,4 @@ public class PfConceptContainer ex + keyFieldValue + " does not match the value " + conceptField + " in the concept field"); } } -} +} \ No newline at end of file -- cgit 1.2.3-korg