From a65e4772f4557a109917532b2d9c49680ce3bb15 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 14 Sep 2018 16:45:06 +0100 Subject: Fix exception not logged or rethrown Eclipse sonarlint does not check for exception dropping by default, it must be configured. This commit addresses exception dropping in apex. Change-Id: I406838990b3424c2912124b25d7326502cacc96c Issue-ID: POLICY-1034 Signed-off-by: liamfallon --- .../policy/apex/model/policymodel/concepts/AxLogic.java | 8 ++++---- .../policy/apex/model/policymodel/concepts/AxPolicy.java | 13 ++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'model/policy-model/src') diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java index 99642d1ae..ad86fb42c 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java @@ -271,11 +271,11 @@ public class AxLogic extends AxConcept { "logic flavour is not defined")); } - try { - Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP); - } catch (final IllegalArgumentException e) { + String flavourValidationString = Assertions.getStringParameterValidationMessage(LOGIC_FLAVOUR_TOKEN, + logicFlavour, LOGIC_FLAVOUR_REGEXP); + if (flavourValidationString != null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "logic flavour invalid-" + e.getMessage())); + "logic flavour invalid-" + flavourValidationString)); } if (logic.replaceAll(WHITESPACE_REGEXP, "").length() == 0) { diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java index a03b49f13..3c43c6edd 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java @@ -49,6 +49,8 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; import org.onap.policy.apex.model.utilities.Assertions; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; /** * This class holds the definition of an Apex policy. A policy is made up of a tree of states, each represented by an @@ -88,6 +90,9 @@ import org.onap.policy.apex.model.utilities.Assertions; public class AxPolicy extends AxConcept { private static final long serialVersionUID = -1775614096390365941L; + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(AxPolicy.class); + @EmbeddedId @XmlElement(name = "policyKey", required = true) private AxArtifactKey key; @@ -364,7 +369,7 @@ public class AxPolicy extends AxConcept { */ private AxValidationResult validateStateTree(AxValidationResult result) { try { - // Cpnstructor validates policy state tree + // Constructor validates policy state tree AxStateTree policyStateTree = getStateTree(); // Check for unused states @@ -378,8 +383,10 @@ public class AxPolicy extends AxConcept { + " is not referenced in the policy execution tree")); } } catch (PolicyRuntimeException pre) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING, - "state tree in policy is invalid")); + AxValidationMessage validationMessage = new AxValidationMessage(key, this.getClass(), + ValidationResult.WARNING, "state tree in policy is invalid"); + LOGGER.trace(validationMessage.getMessage(), pre); + result.addValidationMessage(validationMessage); } return result; -- cgit 1.2.3-korg