From b6977d2f7ce64ece732ac1a1a0525dac972d7ccf Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 17 Feb 2021 15:23:38 -0500 Subject: Fix sonars in apex-pdp Addressed the following issues: - initialize mocks before use - use parameterized queries - Random() is not secure - provide parameterized type for generics - unused imports - constructor visibility - use compute() instead of containsKey()/put() - make final fields static - rename constants to all upper case - no assert() in Thread.run() methods - nested try - nested if/else - too many break/continue - use try-with-resources - repeatable annotations - overlapping characters in reg ex - hashcode is not sufficient in compareTo() - need equals() with compareTo() - make class an interface - use parameterized test - multiple calls in assert() - log or re-throw - use different type of lambda - use parameterized logging - use StringBuilder instead of concatenation - use StandardCharsets.UTF_8 Issue-ID: POLICY-2906 Change-Id: I2cf8c885e3e22c2c6cbe6403a34906928afad022 Signed-off-by: Jim Hahn --- .../filecarrierplugin/consumer/ApexFileEventConsumer.java | 2 +- .../carriertechnology/CarrierTechnologyParameters.java | 11 ++++++----- .../parameters/eventprotocol/EventProtocolParameters.java | 9 +++++---- .../EventProtocolTextCharDelimitedParameters.java | 9 +++++---- .../EventProtocolTextTokenDelimitedParameters.java | 13 +++++++------ 5 files changed, 24 insertions(+), 20 deletions(-) (limited to 'services/services-engine/src/main') diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumer.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumer.java index 076c50b40..e12e4588e 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumer.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumer.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -129,7 +130,6 @@ public class ApexFileEventConsumer implements ApexEventConsumer, Runnable { final String errorMessage = APEX_FILE_CONSUMER_PREAMBLE + consumerName + "\" failed to open file for reading: \"" + fileCarrierTechnologyParameters.getFileName() + "\""; - LOGGER.warn(errorMessage, e); throw new ApexEventException(errorMessage, e); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java index 5a90f847d..e688aad17 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -28,7 +29,7 @@ import org.onap.policy.common.parameters.ValidationStatus; /** * The default carrier technology parameter class that may be specialized by carrier technology plugins that require * plugin specific parameters. - * + * *

The following parameters are defined:

  1. label: The label of the carrier technology. *
  2. eventProducerPluginClass: The name of the plugin class that will be used by Apex to produce and emit output * events for this carrier technology
  3. eventConsumerPluginClass: The name of the plugin class that will be used by @@ -50,7 +51,7 @@ public abstract class CarrierTechnologyParameters implements ParameterGroup { * Constructor to create a carrier technology parameters instance with the name of a sub class of this class and * register the instance with the parameter service. */ - public CarrierTechnologyParameters() { + protected CarrierTechnologyParameters() { super(); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java index b3a264481..68d5f8a56 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -49,7 +50,7 @@ public abstract class EventProtocolParameters implements ParameterGroup { * Constructor to create an event protocol parameters instance with the name of a sub class of this class and * register the instance with the parameter service. */ - public EventProtocolParameters() { + protected EventProtocolParameters() { super(); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java index 989d3f266..d15d7ed47 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -43,7 +44,7 @@ public abstract class EventProtocolTextCharDelimitedParameters extends EventProt /** * Constructor to create an event protocol parameters instance with the name of a sub class of this class. */ - public EventProtocolTextCharDelimitedParameters() { + protected EventProtocolTextCharDelimitedParameters() { super(); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java index f9328f418..ff363aff6 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -48,7 +49,7 @@ public abstract class EventProtocolTextTokenDelimitedParameters extends EventPro /** * Constructor to create an event protocol parameters instance with the name of a sub class of this class. */ - public EventProtocolTextTokenDelimitedParameters() { + protected EventProtocolTextTokenDelimitedParameters() { super(); } @@ -92,7 +93,7 @@ public abstract class EventProtocolTextTokenDelimitedParameters extends EventPro /** * Check if there must be a delimiter at the start of the first text block. - * + * * @return true if there must be a delimiter at the start of the text block */ public boolean isDelimiterAtStart() { @@ -101,7 +102,7 @@ public abstract class EventProtocolTextTokenDelimitedParameters extends EventPro /** * Sets if there has to be a delimiter at the start of the first text block. - * + * * @param delimiterAtStart * true if there must be a delimiter at the start of the text block */ -- cgit 1.2.3-korg