Reuse Random instances across test benchmark classes#56
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Reuse Random instances across test benchmark classes#56sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZ3eW0KvPF-XYsB0KnQP for java:S2119 rule - AZ3eW0GIPF-XYsB0KnPS for java:S2119 rule - AZ3eW0bzPF-XYsB0KnUv for java:S2119 rule - AZ3eW0CBPF-XYsB0KnN_ for java:S2119 rule - AZ3eW0DHPF-XYsB0KnOY for java:S2119 rule Generated by SonarQube Agent (task: 76b45024-70cf-4905-a430-7d2371c1a97f)
Author
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed 5 critical SonarQube issues (java:S2119) by converting repeated Random instantiations into reusable class-level fields. Creating a new Random object on each method call is inefficient and can produce weak randomness; reusing a single instance per class improves both performance and random number quality.
View Project in SonarCloud
Fixed Issues
java:S2119 - Save and re-use this "Random". • CRITICAL • View issue
Location:
src/main/java/org/owasp/benchmark/testcode/BenchmarkTest00023.java:47Why is this an issue?
Creating a new
Randomobject each time a random value is needed is inefficient and may produce numbers that are not random, depending on the JDK. For better efficiency and randomness, create a singleRandom, store it, and reuse it.What changed
This hunk adds a private field
randomof typejava.util.Randomto the class, so that a singleRandominstance is created once and reused across method invocations. This addresses the inefficiency and potential randomness issue caused by creating a newRandomobject each time a method is called.java:S2119 - Save and re-use this "Random". • CRITICAL • View issue
Location:
src/main/java/org/owasp/benchmark/testcode/BenchmarkTest00399.java:69Why is this an issue?
Creating a new
Randomobject each time a random value is needed is inefficient and may produce numbers that are not random, depending on the JDK. For better efficiency and randomness, create a singleRandom, store it, and reuse it.What changed
This hunk declares a private static
Randomfield at the class level, storing a single reusable instance ofjava.util.Random. This addresses the inefficiency and potential randomness issue caused by creating a newRandomobject each time a method is invoked. By defining theRandominstance as a class-level field, it can be reused across method calls instead of being recreated every time.java:S2119 - Save and re-use this "Random". • CRITICAL • View issue
Location:
src/main/java/org/owasp/benchmark/testcode/BenchmarkTest01060.java:53Why is this an issue?
Creating a new
Randomobject each time a random value is needed is inefficient and may produce numbers that are not random, depending on the JDK. For better efficiency and randomness, create a singleRandom, store it, and reuse it.What changed
This hunk declares a private static
Randomfield at the class level, storing a single reusable instance ofjava.util.Random. This addresses the inefficiency and potential randomness issue caused by creating a newRandomobject each time a method is invoked. By defining theRandominstance as a class-level field, it can be reused across method calls instead of being recreated every time.java:S2119 - Save and re-use this "Random". • CRITICAL • View issue
Location:
src/main/java/org/owasp/benchmark/testcode/BenchmarkTest02140.java:48Why is this an issue?
Creating a new
Randomobject each time a random value is needed is inefficient and may produce numbers that are not random, depending on the JDK. For better efficiency and randomness, create a singleRandom, store it, and reuse it.What changed
This hunk declares a private static final Random field at the class level, storing a single reusable instance of java.util.Random. This addresses the inefficiency and potential randomness issue caused by creating a new Random object each time a method is invoked. By defining the Random instance as a class-level field, it can be reused across method calls rather than being recreated every time.
java:S2119 - Save and re-use this "Random". • CRITICAL • View issue
Location:
src/main/java/org/owasp/benchmark/testcode/BenchmarkTest02503.java:50Why is this an issue?
Creating a new
Randomobject each time a random value is needed is inefficient and may produce numbers that are not random, depending on the JDK. For better efficiency and randomness, create a singleRandom, store it, and reuse it.What changed
This hunk declares a private static final Random field at the class level, storing a single reusable instance of java.util.Random. This addresses the inefficiency and potential randomness issue caused by creating a new Random object each time a method is invoked. By defining the Random instance as a class-level field, it can be reused across method calls rather than being recreated every time.
SonarQube Remediation Agent uses AI. Check for mistakes.