From 2ebe1aa650c45eed7b7c8a918c99abd0e24b7317 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 14 Nov 2021 10:30:59 +0000 Subject: [PATCH] [github-278] Resolve all SpotBugs P1 issues in Main and Test. Thanks to Andreas Reichel. This closes #278 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895017 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/util/RandomSingleton.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 poi/src/main/java/org/apache/poi/util/RandomSingleton.java diff --git a/poi/src/main/java/org/apache/poi/util/RandomSingleton.java b/poi/src/main/java/org/apache/poi/util/RandomSingleton.java new file mode 100644 index 0000000000..b6b9f59ba8 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/util/RandomSingleton.java @@ -0,0 +1,19 @@ +package org.apache.poi.util; + +import java.security.SecureRandom; + +/* +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). +*/ + +public class RandomSingleton { + private static final SecureRandom INSTANCE = new SecureRandom(); + + public static SecureRandom getInstance() { + return INSTANCE; + } +} -- 2.39.5