You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/02/16 12:26:53 UTC

[camel] 01/02: CAMEL-16218 - Mark use of java.util.Random with NOSONAR to not have false flags in code analysis reports

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a90d32afe73daae33acfd675bd6ef711255fe360
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Feb 16 13:15:30 2021 +0100

    CAMEL-16218 - Mark use of java.util.Random with NOSONAR to not have false flags in code analysis reports
---
 .../java/org/apache/camel/language/csimple/CSimpleHelper.java     | 3 +--
 .../org/apache/camel/language/simple/SimpleExpressionBuilder.java | 6 ++----
 .../org/apache/camel/processor/errorhandler/RedeliveryPolicy.java | 8 +++-----
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
index 7041e29..4786e2b 100644
--- a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
+++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
@@ -465,8 +465,7 @@ public final class CSimpleHelper {
     public static int random(Exchange exchange, Object min, Object max) {
         int num1 = exchange.getContext().getTypeConverter().tryConvertTo(int.class, exchange, min);
         int num2 = exchange.getContext().getTypeConverter().tryConvertTo(int.class, exchange, max);
-        // NOSONAR
-        Random random = new Random();
+        Random random = new Random(); // NOSONAR
         return random.nextInt(num2 - num1) + num1;
     }
 
diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java
index 9844780..47f2857 100644
--- a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java
+++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/SimpleExpressionBuilder.java
@@ -190,8 +190,7 @@ public final class SimpleExpressionBuilder {
             public Object evaluate(Exchange exchange) {
                 int num1 = exp1.evaluate(exchange, Integer.class);
                 int num2 = exp2.evaluate(exchange, Integer.class);
-                // NOSONAR
-                Random random = new Random();
+                Random random = new Random(); // NOSONAR
                 int randomNum = random.nextInt(num2 - num1) + num1;
                 return randomNum;
             }
@@ -224,8 +223,7 @@ public final class SimpleExpressionBuilder {
     public static Expression randomExpression(final int min, final int max) {
         return new ExpressionAdapter() {
             public Object evaluate(Exchange exchange) {
-                // NOSONAR
-                Random random = new Random();
+                Random random = new Random(); // NOSONAR
                 int randomNum = random.nextInt(max - min) + min;
                 return randomNum;
             }
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryPolicy.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryPolicy.java
index 27cabda..233bdc0 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryPolicy.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryPolicy.java
@@ -230,9 +230,8 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
             /*
              * First random determines +/-, second random determines how far to
              * go in that direction. -cgs
-             */
-            // NOSONAR
-            Random random = getRandomNumberGenerator();
+             */ 
+            Random random = getRandomNumberGenerator(); // NOSONAR
             double variance = (random.nextBoolean() ? collisionAvoidanceFactor : -collisionAvoidanceFactor)
                               * random.nextDouble();
             redeliveryDelayResult += redeliveryDelayResult * variance;
@@ -564,8 +563,7 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
 
     protected static synchronized Random getRandomNumberGenerator() {
         if (randomNumberGenerator == null) {
-            // NOSONAR
-            randomNumberGenerator = new Random();
+            randomNumberGenerator = new Random(); // NOSONAR
         }
         return randomNumberGenerator;
     }