Skip to content

Commit 84247d3

Browse files
authored
Improve SecureRandom usage in ObjectId (#1394)
1 parent b42d76b commit 84247d3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

bson/src/main/org/bson/types/ObjectId.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final class ObjectId implements Comparable<ObjectId>, Serializable {
5757
private static final int RANDOM_VALUE1;
5858
private static final short RANDOM_VALUE2;
5959

60-
private static final AtomicInteger NEXT_COUNTER = new AtomicInteger(new SecureRandom().nextInt());
60+
private static final AtomicInteger NEXT_COUNTER;
6161

6262
private static final char[] HEX_CHARS = {
6363
'0', '1', '2', '3', '4', '5', '6', '7',
@@ -409,6 +409,7 @@ private Object readResolve() {
409409
SecureRandom secureRandom = new SecureRandom();
410410
RANDOM_VALUE1 = secureRandom.nextInt(0x01000000);
411411
RANDOM_VALUE2 = (short) secureRandom.nextInt(0x00008000);
412+
NEXT_COUNTER = new AtomicInteger(secureRandom.nextInt());
412413
} catch (Exception e) {
413414
throw new RuntimeException(e);
414415
}

0 commit comments

Comments
 (0)