Skip to content

Commit

Permalink
JENKINS-8660: loading the build history cause an NPE on the History W…
Browse files Browse the repository at this point in the history
…idget

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)
  • Loading branch information
lacostej committed Feb 3, 2011
1 parent 5150e71 commit 9a13990
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/widgets/HistoryWidget.java
Expand Up @@ -151,6 +151,8 @@ public void setTrimmed(boolean trimmed) {
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
Expand Down
17 changes: 11 additions & 6 deletions core/src/main/resources/hudson/widgets/HistoryWidget/index.jelly
Expand Up @@ -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");
Expand All @@ -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);
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions war/src/main/webapp/scripts/hudson-behavior.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 9a13990

Please sign in to comment.