Skip to content
Permalink
Browse files

[JENKINS-15156] Found a problem with uninitialized run maps in new Ma…

…ven modules.

Not observed in actual usage, but reproducible (for me at least, though apparently not ci.jenkins-ci.org) in a test:
java.lang.AssertionError: null
    at jenkins.model.lazy.AbstractLazyLoadRunMap.load(AbstractLazyLoadRunMap.java:628)
    at jenkins.model.lazy.AbstractLazyLoadRunMap.all(AbstractLazyLoadRunMap.java:581)
    at jenkins.model.lazy.AbstractLazyLoadRunMap.entrySet(AbstractLazyLoadRunMap.java:243)
    at java.util.AbstractMap$2$1.<init>(AbstractMap.java:378)
    at java.util.AbstractMap$2.iterator(AbstractMap.java:377)
    at hudson.util.RunList.iterator(RunList.java:103)
    at hudson.util.RunList.size(RunList.java:114)
    at hudson.maven.MavenProjectTest.testDeleteSetBuildDeletesModuleBuilds(MavenProjectTest.java:159)
  • Loading branch information
jglick committed Feb 21, 2013
1 parent fd0657e commit 09c7cf6ad7cfb4d88d6d8936f29b13f3ca187875
@@ -88,7 +88,6 @@
import jenkins.scm.SCMCheckoutStrategyDescriptor;
import jenkins.util.TimeDuration;
import net.sf.json.JSONObject;
import org.apache.tools.ant.taskdefs.email.Mailer;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.args4j.Argument;
@@ -989,6 +988,7 @@ public BuildAuthorizationToken getAuthToken() {

@Override
public RunMap<R> _getRuns() {
assert builds.baseDirInitialized() : "neither onCreatedFromScratch nor onLoad called on " + this + " yet";
return builds;
}

@@ -23,7 +23,9 @@
*/
package jenkins.model.lazy;

import hudson.model.Job;
import hudson.model.Run;
import hudson.model.RunMap;
import org.apache.commons.collections.keyvalue.DefaultMapEntry;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -200,6 +202,14 @@ protected void initBaseDir(File dir) {
loadIdOnDisk();
}

/**
* @return true if {@link AbstractLazyLoadRunMap#AbstractLazyLoadRunMap} was called with a non-null param, or {@link RunMap#load(Job, RunMap.Constructor)} was called
*/
@Restricted(NoExternalUse.class)
public final boolean baseDirInitialized() {
return dir != null;
}

private void loadIdOnDisk() {
String[] buildDirs = dir.list(createDirectoryFilter());
if (buildDirs==null) {
@@ -240,6 +250,7 @@ public boolean isEmpty() {

@Override
public Set<Entry<Integer, R>> entrySet() {
assert baseDirInitialized();
return Collections.unmodifiableSet(new BuildReferenceMapAdapter<R>(this,all()).entrySet());
}

@@ -905,6 +905,7 @@ private void parsePoms(BuildListener listener, PrintStream logger, EnvVars envVa
} else {// this looks like a new module
logger.println(Messages.MavenModuleSetBuild_DiscoveredModule(pom.name,pom.displayName));
mm = new MavenModule(project,pom,getNumber());
mm.onCreatedFromScratch();
modules.put(mm.getModuleName(),mm);
needsDependencyGraphRecalculation = true;
}

0 comments on commit 09c7cf6

Please sign in to comment.
You can’t perform that action at this time.