Fix sonar issues in apex-pdp 72/123672/5
authorRam Krishna Verma <ram_krishna.verma@bell.ca>
Fri, 27 Aug 2021 20:53:11 +0000 (16:53 -0400)
committerAjith Sreekumar <ajith.sreekumar@bell.ca>
Tue, 31 Aug 2021 10:14:34 +0000 (10:14 +0000)
Issue-ID: POLICY-3077
Change-Id: Id5e7c2ddada2bac3b73fe543f9adade6f9b83e6c
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
18 files changed:
context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java
context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFlushTimerTask.java
context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.java
context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.java
context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java
context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java
core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java
core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java
core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java
core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java
core/core-engine/src/main/java/org/onap/policy/apex/core/engine/monitoring/EventMonitor.java
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java

index 431c387..9f18475 100644 (file)
@@ -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.
@@ -53,8 +54,8 @@ public class DistributorFactory {
         Assertions.argumentOfClassNotNull(key, ContextException.class, "Parameter \"key\" may not be null");
 
         // Get the class for the distributor using reflection
-        final DistributorParameters distributorParameters =
-                ParameterService.get(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
+        final var distributorParameters =
+                        (DistributorParameters) ParameterService.get(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
         final String pluginClass = distributorParameters.getPluginClass();
         Object contextDistributorObject = null;
         try {
@@ -73,7 +74,7 @@ public class DistributorFactory {
         }
 
         // The context Distributor to return
-        final Distributor contextDistributor = (Distributor) contextDistributorObject;
+        final var contextDistributor = (Distributor) contextDistributorObject;
 
         // Lock and load the context distributor
         contextDistributor.init(key);
index e98e661..bd31059 100644 (file)
@@ -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.
@@ -64,8 +65,8 @@ public class DistributorFlushTimerTask extends TimerTask {
         this.contextDistributor = contextDistributor;
 
         // Set the period for persistence flushing
-        final PersistorParameters persistorParameters = ParameterService
-                        .get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
+        final var persistorParameters =
+                        (PersistorParameters) ParameterService.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
         flushPeriod = persistorParameters.getFlushPeriod();
 
         // Set up the timer
index 923c839..9aac801 100644 (file)
@@ -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.
@@ -50,8 +51,8 @@ public class LockManagerFactory {
     public LockManager createLockManager(final AxArtifactKey key) throws ContextException {
         LOGGER.entry("Lock Manager factory, key=" + key);
 
-        final LockManagerParameters lockManagerParameters =
-                ParameterService.get(ContextParameterConstants.LOCKING_GROUP_NAME);
+        final var lockManagerParameters =
+                        (LockManagerParameters) ParameterService.get(ContextParameterConstants.LOCKING_GROUP_NAME);
 
         // Get the class for the lock manager using reflection
         Object lockManagerObject = null;
@@ -76,7 +77,7 @@ public class LockManagerFactory {
         }
 
         // The context lock manager to return
-        final LockManager lockManager = (LockManager) lockManagerObject;
+        final var lockManager = (LockManager) lockManagerObject;
 
         // Lock and load (OK sorry!!!) the lock manager
         lockManager.init(key);
index fe06d2f..31a31b5 100644 (file)
@@ -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.
@@ -51,8 +52,8 @@ public class PersistorFactory {
         LOGGER.entry("persistor factory, key=" + key);
         Assertions.argumentOfClassNotNull(key, ContextException.class, "Parameter \"key\" may not be null");
 
-        final PersistorParameters persistorParameters =
-                ParameterService.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
+        final var persistorParameters =
+                        (PersistorParameters) ParameterService.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
 
         // Get the class for the persistor using reflection
         Object persistorObject = null;
@@ -75,7 +76,7 @@ public class PersistorFactory {
         }
 
         // The persistor to return
-        final Persistor persistor = (Persistor) persistorObject;
+        final var persistor = (Persistor) persistorObject;
 
         // Lock and load the persistor
         persistor.init(key);
index a5fa268..08289e6 100644 (file)
@@ -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.
@@ -24,7 +25,6 @@ package org.onap.policy.apex.context.impl.schema;
 import org.onap.policy.apex.context.ContextRuntimeException;
 import org.onap.policy.apex.context.SchemaHelper;
 import org.onap.policy.apex.context.parameters.ContextParameterConstants;
-import org.onap.policy.apex.context.parameters.SchemaHelperParameters;
 import org.onap.policy.apex.context.parameters.SchemaParameters;
 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
@@ -70,10 +70,11 @@ public class SchemaHelperFactory {
         }
 
         // Get the schema class using the parameter service
-        final SchemaParameters schemaParameters = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME);
+        final var schemaParameters =
+                        (SchemaParameters) ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME);
 
         // Get the class for the schema helper from the schema parameters
-        final SchemaHelperParameters schemaHelperParameters =
+        final var schemaHelperParameters =
                 schemaParameters.getSchemaHelperParameters(schema.getSchemaFlavour());
         if (schemaHelperParameters == null) {
             final var resultString = "context schema helper parameters not found for context schema  \""
@@ -103,7 +104,7 @@ public class SchemaHelperFactory {
         }
 
         // The context schema helper to return
-        final SchemaHelper schemaHelper = (SchemaHelper) schemaHelperObject;
+        final var schemaHelper = (SchemaHelper) schemaHelperObject;
 
         // Lock and load the schema helper
         schemaHelper.init(owningEntityKey.getKey(), schema);
index 7d67788..f601062 100644 (file)
@@ -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.
@@ -234,10 +235,10 @@ public class JavaSchemaHelper extends AbstractSchemaHelper {
      * @return the GSON instance
      */
     private Gson getGson() {
-        GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting();
+        var gsonBuilder = new GsonBuilder().setPrettyPrinting();
 
         // Get the Java schema helper parameters from the parameter service
-        SchemaParameters schemaParameters = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME);
+        var schemaParameters = (SchemaParameters) ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME);
 
         JavaSchemaHelperParameters javaSchemaHelperParmeters =
                 (JavaSchemaHelperParameters) schemaParameters.getSchemaHelperParameterMap().get("Java");
index 3f6d6cf..6cbc046 100644 (file)
@@ -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) {
index eb5f5f3..12e3503 100644 (file)
@@ -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) {
index 69d51c4..c79e907 100644 (file)
@@ -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) {
index e37d074..9dc841f 100644 (file)
@@ -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);
index de2639d..ca564ca 100644 (file)
@@ -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;
index e3a51f0..49e7d1e 100644 (file)
@@ -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()) {
index 5cc3f21..783ac4c 100644 (file)
@@ -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());
index 1bc1000..0cdf76f 100644 (file)
@@ -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();
 
index 55b2e36..8b6d0c6 100644 (file)
@@ -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) {
index ba84ca0..071a6cf 100644 (file)
@@ -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);
index dd8b829..9345aba 100644 (file)
@@ -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;
index f209073..2f863d0 100644 (file)
@@ -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);