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.
  • Loading branch information
jglick committed Oct 16, 2013
1 parent 4488e6c commit 587c6fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -58,6 +58,9 @@
<li class='rfe'>
Upgrade bundled plugin versions: ssh-slaves to 1.5, and credentials to 1.9.1
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20071">issue 20071</a>)
<li class=bug>
Integer overflow could cause JavaScript functions to break in long-running Jenkins processes.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20085">issue 20085</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
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 587c6fe

Please sign in to comment.