提交 9a13990b 编写于 作者: J Jerome Lacoste

JENKINS-8660: loading the build history cause an NPE on the History Widget

loadAllBuildHistory() fails to set the headers field on the replacement buildHistory DOM element.

The patch fixes the problem by recreating a headers field.
It also:
* slightly refactor the loadAllBuildHistory() method for readability
* add a FIXME note that the server side history widget should fail if the n parameter is missing.
* add a pre-condition check to the buildHistory() update to catch potential bugs (note that the logging is disabled as Yahoo.log doesn't appear available)
上级 5150e710
......@@ -151,6 +151,8 @@ public class HistoryWidget<O extends ModelObject,T> extends Widget {
public void doAjax( StaplerRequest req, StaplerResponse rsp,
@Header("n") String n ) throws IOException, ServletException {
// FIXME n can be null if the client behave incorrectly. We should fail gracefully (404?) instead of NPEing
rsp.setContentType("text/html;charset=UTF-8");
// pick up builds to send back
......
......@@ -48,6 +48,13 @@ THE SOFTWARE.
<tr class="build-row">
<td colspan="3" align="right">
<script>
function replace(a, b) {
var p = a.parentNode;
var next = a.nextSibling;
p.removeChild(a);
p.insertBefore(b,next);
}
function loadAllBuildHistory() {
// first display the "loading..." icon
var box = $("loadAllBuildHistory");
......@@ -59,14 +66,12 @@ THE SOFTWARE.
onComplete: function(rsp,_) {
<!-- neither outerHTML nor responseXML works in Firefox 2.0 -->
var hist = $$("buildHistory");
var p = hist.parentNode;
var next = hist.nextSibling;
p.removeChild(hist);
var div = document.createElement('div');
div.innerHTML = rsp.responseText;
var newhist = document.createElement('div');
newhist.innerHTML = rsp.responseText;
newhist.headers = hist.headers
p.insertBefore(div,next);
replace(hist, newhist);
}
});
}
......
......@@ -1472,6 +1472,9 @@ function updateBuildHistory(ajaxUrl,nBuild) {
function updateBuilds() {
var bh = $('buildHistory');
if (bh.headers == null) {
// Yahoo.log("Missing headers in buildHistory element");
}
new Ajax.Request(ajaxUrl, {
requestHeaders: bh.headers,
onSuccess: function(rsp) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册