提交 06c211c6 编写于 作者: J Jesse Glick

[JENKINS-17728] Fixing another possible cause of an NPE.

Unlike the bug I originally reproduced, in which the parent had some builds
but the context in which the new build was scheduled omits a parent,
this seems to be due to a case in which there is no build record at all for the parent.
No idea how that could happen (getLastBuild should return even a running, failed, or aborted build),
but @treydock reports a stack trace in 1.509.2 which implies this.
So fixing null safety; will not prevent an exception but will report it more gracefully.
上级 50ddd4c6
......@@ -55,7 +55,9 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
Fixed another possible cause of an NPE from MatrixConfiguration.newBuild.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17728">issue 17728</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -239,6 +239,10 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun>
}
}
if (lb == null) {
throw new IOException("cannot start a build of " + getFullName() + " since its parent has no builds at all");
}
// for every MatrixRun there should be a parent MatrixBuild
MatrixRun lastBuild = new MatrixRun(this, lb.getTimestamp());
......
......@@ -135,6 +135,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import static hudson.scm.PollingResult.*;
import javax.annotation.CheckForNull;
import static javax.servlet.http.HttpServletResponse.*;
/**
......@@ -1061,7 +1062,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
@Override
public R getLastBuild() {
public @CheckForNull R getLastBuild() {
return builds.newestBuild();
}
......
......@@ -46,6 +46,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import static jenkins.model.lazy.AbstractLazyLoadRunMap.Direction.*;
import static jenkins.model.lazy.Boundary.*;
......@@ -353,7 +354,7 @@ public abstract class AbstractLazyLoadRunMap<R> extends AbstractMap<Integer,R> i
* If ASC, finds the closest #M that satisfies M>=N.
* If DESC, finds the closest #M that satisfies M&lt;=N.
*/
public R search(final int n, final Direction d) {
public @CheckForNull R search(final int n, final Direction d) {
Entry<Integer, BuildReference<R>> c = index.ceilingEntry(n);
if (c!=null && c.getKey()== n) {
R r = c.getValue().get();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册