Skip to content

Commit 49356b2

Browse files
committed
SimpleIdGenerator rolls over at Long.MAX_VALUE
Closes gh-25485
1 parent 852718e commit 49356b2

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

spring-core/src/main/java/org/springframework/util/SimpleIdGenerator.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,25 +20,20 @@
2020
import java.util.concurrent.atomic.AtomicLong;
2121

2222
/**
23-
* A simple {@link IdGenerator} that starts at 1 and increments by 1 with each call.
23+
* A simple {@link IdGenerator} that starts at 1, increments up to
24+
* {@link Long#MAX_VALUE}, and then rolls over.
2425
*
2526
* @author Rossen Stoyanchev
2627
* @since 4.1.5
2728
*/
2829
public class SimpleIdGenerator implements IdGenerator {
2930

30-
private final AtomicLong mostSigBits = new AtomicLong(0);
31-
3231
private final AtomicLong leastSigBits = new AtomicLong(0);
3332

3433

3534
@Override
3635
public UUID generateId() {
37-
long leastSigBits = this.leastSigBits.incrementAndGet();
38-
if (leastSigBits == 0) {
39-
this.mostSigBits.incrementAndGet();
40-
}
41-
return new UUID(this.mostSigBits.get(), leastSigBits);
36+
return new UUID(0, this.leastSigBits.incrementAndGet());
4237
}
4338

4439
}

0 commit comments

Comments
 (0)