Skip to content

Commit

Permalink
[FIXED JENKINS-20085] Overflow in Jenkins.globalIota. Simpler and saf…
Browse files Browse the repository at this point in the history
…er to use an AtomicLong.

(cherry picked from commit 587c6fe)

Conflicts:
	changelog.html
  • Loading branch information
jglick authored and olivergondza committed Nov 2, 2013
1 parent 1bb06ad commit 3859b83
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions core/src/main/java/hudson/Functions.java
Expand Up @@ -150,6 +150,7 @@

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import java.util.concurrent.atomic.AtomicLong;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;

Expand All @@ -164,21 +165,16 @@
*/
@SuppressWarnings("rawtypes")
public class Functions {
private static volatile int globalIota = 0;
private int iota;
private static final AtomicLong iota = new AtomicLong();

public Functions() {
iota = globalIota;
// concurrent requests can use the same ID --- we are just trying to
// prevent the same user from seeing the same ID repeatedly.
globalIota+=1000;
}

/**
* Generates an unique ID.
*/
public String generateId() {
return "id"+iota++;
return "id" + iota.getAndIncrement();
}

public static boolean isModel(Object o) {
Expand Down

0 comments on commit 3859b83

Please sign in to comment.