summaryrefslogtreecommitdiffstats
path: root/core/core-infrastructure
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2021-08-27 16:53:11 -0400
committerAjith Sreekumar <ajith.sreekumar@bell.ca>2021-08-31 10:14:34 +0000
commit9ee4561bcd28b7199fd1ffed118f122a8435203a (patch)
tree49f07ddc8d082f6028fb53dbfcfeb654b79a55a3 /core/core-infrastructure
parent795bd98b7459fd677e06354ea054c8922821522b (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/core-infrastructure')
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java12
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java5
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java5
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java5
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java11
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java3
-rw-r--r--core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java6
7 files changed, 26 insertions, 21 deletions
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);