From 6945b75aac0e6bc2bad6f824769b32842f06bc46 Mon Sep 17 00:00:00 2001 From: Liard Samuel Date: Fri, 8 Oct 2021 09:21:18 +0200 Subject: Fix sonar Security Hotspots Issue-ID: CCSDK-3491 Signed-off-by: sliard Change-Id: I33787ccca2a8acd8085db6b2a915e8f2ac2511ec Signed-off-by: Dan Timoney Signed-off-by: highstreetherbert --- .../main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java | 1 + .../java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java | 4 +++- .../test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/rlock/src') diff --git a/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java b/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java index 63fe111df..a63b7d481 100644 --- a/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java +++ b/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/LockHelperImpl.java @@ -84,6 +84,7 @@ public class LockHelperImpl implements LockHelper { try { Thread.sleep(lockWait * 1000L); } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); } } } diff --git a/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java b/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java index e92700055..419977890 100644 --- a/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java +++ b/lib/rlock/src/main/java/org/onap/ccsdk/features/lib/rlock/SynchronizedFunction.java @@ -1,5 +1,6 @@ package org.onap.ccsdk.features.lib.rlock; +import java.security.SecureRandom; import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -99,6 +100,7 @@ public abstract class SynchronizedFunction { } private static String generateLockRequester() { - return "SynchronizedFunction-" + (int) (Math.random() * 1000000); + SecureRandom random = new SecureRandom(); + return "SynchronizedFunction-" + (random.nextInt() % 1000000); } } diff --git a/lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java b/lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java index cce377e2c..4f205d16d 100644 --- a/lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java +++ b/lib/rlock/src/test/java/org/onap/ccsdk/features/lib/rlock/TestLockHelper.java @@ -42,6 +42,7 @@ public class TestLockHelper { try { Thread.sleep(500); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); log.warn("Thread interrupted: " + e.getMessage(), e); } -- cgit 1.2.3-korg