aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2024-08-12 21:18:12 +0100
committerwaynedunican <wayne.dunican@est.tech>2024-08-13 09:21:16 +0100
commit63d23a4aa0f3aeae9d6470b95dfa8f87b2d85aa8 (patch)
tree74aa5c14f66dc5760eb00ea8f18c278174cbc56e /common-logging/src
parent34cad0af615db1ed4b85b8e4e1b77d0948289eed (diff)
Fix sonar issues in common
- SONAR Fix instanceOf issues - SONAR Remove public modifiers - SONAR Remove unused imports - SONAR Remove exceptions that can't be thrown from method body Issue-ID: POLICY-5106 Change-Id: I745d0101036d3421f02db22481514be0b79f5103 Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'common-logging/src')
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java4
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java11
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java1
3 files changed, 9 insertions, 7 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
index 87a96a19..bdd67a08 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
@@ -3,6 +3,7 @@
* ONAP-Logging
* ================================================================================
* Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,8 +61,7 @@ public class EventData {
if (obj == null) {
return false;
}
- if (obj instanceof String) {
- String otherRequestId = (String) obj;
+ if (obj instanceof String otherRequestId) {
return requestId != null && requestId.equals(otherRequestId);
}
if (getClass() != obj.getClass()) {
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
index 6c301712..7bfcb5d4 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
@@ -3,7 +3,7 @@
* ONAP-Logging
* ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener;
/**
* FlexLogger acts as factory to generate instances of Logger based on logger type.
*/
-public class FlexLogger extends SecurityManager {
+public class FlexLogger {
private static final String GET_LOGGER_PREFIX = "FlexLogger:getLogger : loggerType = ";
private static LoggerType loggerType = LoggerType.EELF;
@@ -95,8 +95,11 @@ public class FlexLogger extends SecurityManager {
* Returns the calling class name.
*/
public String getClassName() {
- displayMessage("getClassContext()[3].getName() " + getClassContext()[3].getName());
- return getClassContext()[3].getName();
+ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ if (stackTrace.length > 3) {
+ return stackTrace[3].getClassName();
+ }
+ return "UnknownClass";
}
/**
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
index 547f0a4a..3c78785b 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
@@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
-import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;