提交 587c6fe3 编写于 作者: J Jesse Glick

[FIXED JENKINS-20085] Overflow in Jenkins.globalIota. Simpler and safer to use an AtomicLong.

上级 4488e6c6
......@@ -58,6 +58,9 @@ Upcoming changes</a>
<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=-->
......
......@@ -150,6 +150,7 @@ import org.kohsuke.stapler.jelly.InternationalizedStringExpression.RawHtmlArgume
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;
......@@ -164,21 +165,16 @@ import org.kohsuke.accmod.restrictions.DoNotUse;
*/
@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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册