From 587c6fe317bfe3560069ceb41495c6f5f5d114d1 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 16 Oct 2013 13:40:34 -0400 Subject: [PATCH] [FIXED JENKINS-20085] Overflow in Jenkins.globalIota. Simpler and safer to use an AtomicLong. --- changelog.html | 3 +++ core/src/main/java/hudson/Functions.java | 10 +++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/changelog.html b/changelog.html index c04032e684..30159c9653 100644 --- a/changelog.html +++ b/changelog.html @@ -58,6 +58,9 @@ Upcoming changes
  • Upgrade bundled plugin versions: ssh-slaves to 1.5, and credentials to 1.9.1 (issue 20071) +
  • + Integer overflow could cause JavaScript functions to break in long-running Jenkins processes. + (issue 20085) diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 190143f55d..897f514b42 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -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) {