diff options
author | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2021-08-27 16:53:11 -0400 |
---|---|---|
committer | Ajith Sreekumar <ajith.sreekumar@bell.ca> | 2021-08-31 10:14:34 +0000 |
commit | 9ee4561bcd28b7199fd1ffed118f122a8435203a (patch) | |
tree | 49f07ddc8d082f6028fb53dbfcfeb654b79a55a3 /core | |
parent | 795bd98b7459fd677e06354ea054c8922821522b (diff) |
Fix sonar issues in apex-pdp
Issue-ID: POLICY-3077
Change-Id: Id5e7c2ddada2bac3b73fe543f9adade6f9b83e6c
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
Diffstat (limited to 'core')
12 files changed, 41 insertions, 32 deletions
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java index 3f6d6cfe6..6cbc04678 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java @@ -93,7 +93,7 @@ public class StateMachineExecutor implements Executor<EnEvent, Collection<EnEven StateExecutor lastExecutor = null; for (final AxState state : axPolicy.getStateMap().values()) { // Create a state executor for this state and add its context (the state) - final StateExecutor stateExecutor = new StateExecutor(executorFactory); + final var stateExecutor = new StateExecutor(executorFactory); stateExecutor.setContext(this, state, internalContext); // Update the next executor on the last executor @@ -140,8 +140,8 @@ public class StateMachineExecutor implements Executor<EnEvent, Collection<EnEven // Get the first state of the state machine and define a state output that starts state // execution - StateExecutor stateExecutor = firstExecutor; - StateOutput stateOutput = new StateOutput(new AxStateOutput(firstExecutor.getSubject().getKey(), + var stateExecutor = firstExecutor; + var stateOutput = new StateOutput(new AxStateOutput(firstExecutor.getSubject().getKey(), incomingEvent.getKey(), firstExecutor.getSubject().getKey()), incomingEvent); while (true) { diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java index eb5f5f35d..12e350390 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java @@ -3,6 +3,7 @@ * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020-2021 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -150,7 +151,7 @@ public class StateFinalizerExecutionContext extends AbstractExecutionContext { */ public ContextAlbum getContextAlbum(final String contextAlbumName) { // Find the context album - final ContextAlbum foundContextAlbum = context.get(contextAlbumName); + final var foundContextAlbum = context.get(contextAlbumName); // Check if the context album exists if (foundContextAlbum != null) { diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java index 69d51c45a..c79e907d9 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java @@ -3,6 +3,7 @@ * 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. + * Modifications Copyright (C) 2021 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. @@ -138,7 +139,7 @@ public class TaskSelectionExecutionContext extends AbstractExecutionContext { */ public ContextAlbum getContextAlbum(final String contextAlbumName) { // Find the context album - final ContextAlbum foundContextAlbum = context.get(contextAlbumName); + final var foundContextAlbum = context.get(contextAlbumName); // Check if the context album exists if (foundContextAlbum != null) { diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java index e37d074b6..9dc841f48 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -117,7 +118,7 @@ public class ExecutorFactoryImpl implements ExecutorFactory { public TaskExecutor getTaskExecutor(final Executor<?, ?, ?, ?> parentExecutor, final AxTask task, final ApexInternalContext context) { // Create task executor - final TaskExecutor taskExecutor = (TaskExecutor) createExecutor(task.getTaskLogic().getLogicFlavour(), + final var taskExecutor = (TaskExecutor) createExecutor(task.getTaskLogic().getLogicFlavour(), taskExecutorPluginClassMap.get(task.getTaskLogic().getLogicFlavour()), TaskExecutor.class); taskExecutor.setParameters(implementationParameterMap.get(task.getTaskLogic().getLogicFlavour())); taskExecutor.setContext(parentExecutor, task, context); diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/monitoring/EventMonitor.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/monitoring/EventMonitor.java index de2639dcb..ca564ca81 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/monitoring/EventMonitor.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/monitoring/EventMonitor.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -44,7 +45,7 @@ public class EventMonitor { * @param userArtifactStack the keys of the artifacts using the event at the moment */ public void monitorGet(final AxField eventParameter, final Object value, final AxConcept[] userArtifactStack) { - String monitorGetString = monitor("GET", userArtifactStack, eventParameter, value); + var monitorGetString = monitor("GET", userArtifactStack, eventParameter, value); LOGGER.trace(monitorGetString); } @@ -56,7 +57,7 @@ public class EventMonitor { * @param userArtifactStack the keys of the artifacts using the event at the moment */ public void monitorSet(final AxField eventParameter, final Object value, final AxConcept[] userArtifactStack) { - String monitorSetString = monitor("SET", userArtifactStack, eventParameter, value); + var monitorSetString = monitor("SET", userArtifactStack, eventParameter, value); LOGGER.trace(monitorSetString); } @@ -69,7 +70,7 @@ public class EventMonitor { */ public void monitorRemove(final AxField eventParameter, final Object removedValue, final AxConcept[] userArtifactStack) { - String monitorRemoveString = monitor("REMOVE", userArtifactStack, eventParameter, removedValue); + var monitorRemoveString = monitor("REMOVE", userArtifactStack, eventParameter, removedValue); LOGGER.trace(monitorRemoveString); } @@ -84,13 +85,13 @@ public class EventMonitor { */ private String monitor(final String preamble, final AxConcept[] userArtifactStack, final AxField eventParameter, final Object value) { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); builder.append(preamble); builder.append(",["); if (userArtifactStack != null) { - boolean first = true; + var first = true; for (final AxConcept stackKey : userArtifactStack) { if (first) { first = false; diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java index e3a51f085..49e7d1e2e 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -26,7 +27,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.Arrays; @@ -72,7 +72,7 @@ public final class ClassUtils { try { // The library path for predefined classes in Java - String sunBootLibraryPathString = System.getProperty(SUN_BOOT_LIBRARY_PATH); + var sunBootLibraryPathString = System.getProperty(SUN_BOOT_LIBRARY_PATH); // Check it exists and has a "lib" in it if (sunBootLibraryPathString != null && sunBootLibraryPathString.contains(LIBRARAY_PATH_TOKEN)) { @@ -80,7 +80,7 @@ public final class ClassUtils { sunBootLibraryPathString = sunBootLibraryPathString.substring(0, sunBootLibraryPathString.lastIndexOf(LIBRARAY_PATH_TOKEN) + LIBRARAY_PATH_TOKEN.length()); - final File bootLibraryFile = new File(sunBootLibraryPathString); + final var bootLibraryFile = new File(sunBootLibraryPathString); // The set used to hold class names is populated with predefined Java classes classNameSet.addAll(processDir(bootLibraryFile, "")); } @@ -96,7 +96,7 @@ public final class ClassUtils { if (url == null || url.getFile() == null) { continue; } - final File urlFile = new File(url.getFile()); + final var urlFile = new File(url.getFile()); // Directories may contain ".class" files if (urlFile.isDirectory()) { classNameSet.addAll(processDir(urlFile, url.getFile())); @@ -121,7 +121,7 @@ public final class ClassUtils { return urls; } - Method mmethod = nullclassloader.getMethod("getBootstrapClassPath"); + var mmethod = nullclassloader.getMethod("getBootstrapClassPath"); if (mmethod == null) { return urls; } @@ -234,7 +234,7 @@ public final class ClassUtils { return classPathSet; } // JARs are ZIP files - final ZipInputStream zip = new ZipInputStream(jarInputStream); + final var zip = new ZipInputStream(jarInputStream); // Iterate over each entry in the JAR for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java index 5cc3f21c7..783ac4cac 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.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 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. @@ -75,7 +76,7 @@ public class SingleClassBuilder { final DiagnosticCollector<JavaFileObject> diagnosticListener = new DiagnosticCollector<>(); // Get the Java compiler - final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + final var compiler = ToolProvider.getSystemJavaCompiler(); // Set up the target file manager and call the compiler singleFileManager = new SingleFileManager(compiler, new SingleClassByteCodeFileObject(className)); @@ -84,7 +85,7 @@ public class SingleClassBuilder { // Check if the compilation worked if (Boolean.FALSE.equals(task.call())) { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); for (final Diagnostic<? extends JavaFileObject> diagnostic : diagnosticListener.getDiagnostics()) { builder.append("code:"); builder.append(diagnostic.getCode()); diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java index 1bc100084..0cdf76ffc 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java @@ -3,6 +3,7 @@ * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -92,8 +93,8 @@ public class RawMessageHandler<M> implements WebSocketMessageListener<M>, Runnab // the queue // processing thread - try (final ByteArrayInputStream stream = new ByteArrayInputStream(dataByteBuffer.array()); - final ObjectInputStream ois = new ObjectInputStream(stream)) { + try (final var stream = new ByteArrayInputStream(dataByteBuffer.array()); + final var ois = new ObjectInputStream(stream)) { @SuppressWarnings("unchecked") final MessageHolder<M> messageHolder = (MessageHolder<M>) ois.readObject(); diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java index 55b2e36ff..8b6d0c6a8 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -69,14 +70,14 @@ public class WsStringMessageServer implements WsStringMessager { LOGGER.entry("web socket event consumer server starting . . ."); if (LOGGER.isDebugEnabled()) { - String lanaddress = "unknown"; + var lanaddress = "unknown"; try { lanaddress = MessagingUtils.getLocalHostLanAddress().getHostAddress(); } catch (final UnknownHostException ignore) { LOGGER.debug("Failed to find name of local address name", ignore); } LOGGER.debug("web socket string message server LAN address=" + lanaddress); - String hostaddress = "unknown"; + var hostaddress = "unknown"; try { hostaddress = InetAddress.getLocalHost().getHostAddress(); } catch (final UnknownHostException ignore) { diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java index ba84ca069..071a6cfde 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java @@ -3,6 +3,7 @@ * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -105,7 +106,7 @@ public final class MessagingUtils { * @return true if port is available */ public static boolean isPortAvailable(final int port) { - try (final Socket socket = new Socket("localhost", port)) { + try (final var socket = new Socket("localhost", port)) { return false; } catch (final IOException ignoredException) { LOGGER.trace("Port {} is available", port, ignoredException); @@ -193,13 +194,13 @@ public final class MessagingUtils { // At this point, we did not find a non-loopback address. // Fall back to returning whatever InetAddress.getLocalHost() // returns... - final InetAddress jdkSuppliedAddress = InetAddress.getLocalHost(); + final var jdkSuppliedAddress = InetAddress.getLocalHost(); if (jdkSuppliedAddress == null) { throw new UnknownHostException("The JDK InetAddress.getLocalHost() method unexpectedly returned null."); } return jdkSuppliedAddress; } catch (final Exception e) { - final UnknownHostException unknownHostException = + final var unknownHostException = new UnknownHostException("Failed to determine LAN address: " + e); unknownHostException.initCause(e); throw unknownHostException; @@ -214,8 +215,8 @@ public final class MessagingUtils { */ public static byte[] serializeObject(final Object object) { LOGGER.entry(object.getClass().getName()); - final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(bytesOut)) { + final var bytesOut = new ByteArrayOutputStream(); + try (var oos = new ObjectOutputStream(bytesOut)) { oos.writeObject(object); } catch (final IOException e) { LOGGER.warn("error on object serialization", e); diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java index dd8b8294f..9345abaaa 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 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. @@ -71,7 +72,7 @@ public class ApplicationThreadFactory implements ThreadFactory { * @param threadPriority the thread priority */ public ApplicationThreadFactory(final String nameLocal, final long stackSize, final int threadPriority) { - final SecurityManager s = System.getSecurityManager(); + final var s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); name = APPLICATION_NAME + nameLocal + HYPHEN + NEXT_POOL_NUMBER.getAndIncrement(); this.stackSize = stackSize; diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java index f20907370..2f863d0e3 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.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 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. @@ -26,7 +27,6 @@ import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.slf4j.ext.XLogger; @@ -74,7 +74,7 @@ public class XPathReader { private void init() { try { LOGGER.info("Initializing XPath reader"); - DocumentBuilderFactory df = DocumentBuilderFactory.newInstance(); + var df = DocumentBuilderFactory.newInstance(); df.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); df.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); df.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); @@ -106,7 +106,7 @@ public class XPathReader { */ public Object read(final String expression, final QName returnType) { try { - final XPathExpression xPathExpression = xpath.compile(expression); + final var xPathExpression = xpath.compile(expression); return xPathExpression.evaluate(xmlDocument, returnType); } catch (final XPathExpressionException ex) { LOGGER.error("Failed to read XML file for XPath processing, reason:\n" + ex.getMessage(), ex); |