diff options
author | Jim Hahn <jrh3@att.com> | 2020-04-07 13:34:34 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-04-07 13:41:05 -0400 |
commit | 2385c44c949a28233ce5446b041e9a20f3241380 (patch) | |
tree | 2579566e34b2a83e5a059845cb00fb321f4f5de0 /main/src | |
parent | 0eb710fb03ef8242bad72be8850a2ecbc7a55229 (diff) |
Address sonar issues in PAP
Addressed the following sonar issues in PAP:
- do something with value returned by a method
- use computeIfAbsent; chose to disable the sonar for this,
as it would obfuscate the code
- use RE2 instead of java.util Pattern
Issue-ID: POLICY-2305
Change-Id: If5495d04248211179cd37419cb20fe7d227ab59c
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src')
3 files changed, 14 insertions, 7 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/Publisher.java b/main/src/main/java/org/onap/policy/pap/main/comm/Publisher.java index 6d2d8358..3fbaa99b 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/Publisher.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/Publisher.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -103,7 +103,7 @@ public class Publisher<T> implements Runnable { if (stopNow) { // unblock any other publisher threads - queue.offer(new QueueToken<>(null)); + queue.add(new QueueToken<>(null)); break; } diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java b/main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java index 0565e90a..f64c2694 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/TimerManager.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -303,6 +303,8 @@ public class TimerManager implements Runnable { * @throws InterruptedException if this thread is interrupted while sleeping */ protected void sleep(long timeMs) throws InterruptedException { - stopper.await(timeMs, TimeUnit.MILLISECONDS); + if (stopper.await(timeMs, TimeUnit.MILLISECONDS)) { + logger.info("sleep finishing due to stop()"); + } } } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java index 22da5392..0d8f7033 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -20,6 +20,7 @@ package org.onap.policy.pap.main.rest; +import com.google.re2j.Pattern; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -27,7 +28,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; @@ -347,7 +347,12 @@ public class SessionData { * @throws PfModelException if an error occurred */ public List<PdpGroup> getActivePdpGroupsByPolicyType(ToscaPolicyTypeIdentifier type) throws PfModelException { - List<GroupData> data = type2groups.get(type); + /* + * Cannot use computeIfAbsent() because the enclosed code throws an unchecked + * exception and handling that would obfuscate the code too much, thus disabling + * the sonar. + */ + List<GroupData> data = type2groups.get(type); // NOSONAR if (data == null) { PdpGroupFilter filter = PdpGroupFilter.builder().policyTypeList(Collections.singletonList(type)) .groupState(PdpState.ACTIVE).build(); |