Wei-Chiu Chuang created HBASE-28918:
---------------------------------------

             Summary: Random object created and used only once in 
org.apache.hadoop.hbase.util.LoadTestKVGenerator.getValueForRowColumn(int, 
byte[][])
                 Key: HBASE-28918
                 URL: https://issues.apache.org/jira/browse/HBASE-28918
             Project: HBase
          Issue Type: Bug
            Reporter: Wei-Chiu Chuang


An unrelated spotbug warning popped up in one of precommit test. 
[https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6342/4/artifact/yetus-general-check/output/branch-spotbugs-hbase-server-warnings.html]

 
h2. Bad practice Warnings
||Code||Warning||
|DMI|Random object created and used only once in 
org.apache.hadoop.hbase.util.LoadTestKVGenerator.getValueForRowColumn(int, 
byte[][])|
| |[Bug type DMI_RANDOM_USED_ONLY_ONCE (click for 
details)|https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6342/4/artifact/yetus-general-check/output/branch-spotbugs-hbase-server-warnings.html#DMI_RANDOM_USED_ONLY_ONCE]
In class org.apache.hadoop.hbase.util.LoadTestKVGenerator
In method 
org.apache.hadoop.hbase.util.LoadTestKVGenerator.getValueForRowColumn(int, 
byte[][])
Called method java.util.Random.nextBytes(byte[])
At LoadTestKVGenerator.java:[line 111]|
h1. Details
h2. DMI_RANDOM_USED_ONLY_ONCE: Random object created and used only once

This code creates a java.util.Random object, uses it to generate one random 
number, and then discards the Random object. This produces mediocre quality 
random numbers and is inefficient. If possible, rewrite the code so that the 
Random object is created once and saved, and each time a new random number is 
required invoke a method on the existing Random object to obtain it.

If it is important that the generated Random numbers not be guessable, you 
_must_ not create a new Random for each random number; the values are too 
easily guessable. You should strongly consider using a 
java.security.SecureRandom instead (and avoid allocating a new SecureRandom for 
each random number needed).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to