Skip to content
Permalink
Browse files
[JENKINS-18809] fix NPE on old data deserialization
  • Loading branch information
Greybird committed Dec 24, 2017
1 parent bce510c commit 2515d7756a04fe7dbd828665aa522e872a66bc1b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
@@ -46,10 +46,9 @@
private ClaimBuildFailureAnalyzer BFAClaimer = null;
private String reason;

protected T owner;
protected abstract T getOwner();

AbstractClaimBuildAction(T owner) {
this.owner = owner;
AbstractClaimBuildAction() {
reclaim = false;
}

@@ -92,9 +91,9 @@ public void doClaim(StaplerRequest req, StaplerResponse resp)
if(ClaimBuildFailureAnalyzer.isBFAEnabled()) {
String error = req.getSubmittedForm().getString("errors");
BFAClaimer = new ClaimBuildFailureAnalyzer(error);
if (this.owner instanceof Run)
if (getOwner() instanceof Run)
{
Run run = (Run) owner;
Run run = (Run) getOwner();
if(!BFAClaimer.isDefaultError()){
try{
BFAClaimer.createFailAction(run);
@@ -114,25 +113,26 @@ public void doClaim(StaplerRequest req, StaplerResponse resp)
if (StringUtils.isEmpty(reason)) reason = null;
claim(name, reason, currentUser, sticky);
try {
ClaimEmailer.sendEmailIfConfigured(User.get(name, false, Collections.EMPTY_MAP), currentUser, owner.toString(), reason, getUrl());
ClaimEmailer.sendEmailIfConfigured(User.get(name, false, Collections.EMPTY_MAP), currentUser, getOwner().toString(), reason, getUrl());
} catch (MessagingException e) {
LOGGER.log(Level.WARNING, "Exception encountered sending assignment email: " + e.getMessage());
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Interrupted when sending assignment email",e);
}
reclaim = true;
owner.save();
this.getOwner().save();
evalGroovyScript();
resp.forwardToPreviousPage(req);
}

public void doUnclaim(StaplerRequest req, StaplerResponse resp)
throws ServletException, IOException {
unclaim();

if(ClaimBuildFailureAnalyzer.isBFAEnabled() && BFAClaimer!=null)
BFAClaimer.removeFailAction((Run) owner);
BFAClaimer.removeFailAction((Run) getOwner());
reclaim = false;
owner.save();
getOwner().save();
evalGroovyScript();
resp.forwardToPreviousPage(req);
}
@@ -1,16 +1,13 @@
package hudson.plugins.claim;

import hudson.model.Run;
import jenkins.model.RunAction2;

public class ClaimBuildAction extends AbstractClaimBuildAction<Run> {
public class ClaimBuildAction extends AbstractClaimBuildAction<Run> implements RunAction2 {

private static final long serialVersionUID = 1L;

private transient Run run;

public ClaimBuildAction(Run run) {
super(run);
}
private transient Run owner;

public String getDisplayName() {
return Messages.ClaimBuildAction_DisplayName();
@@ -21,16 +18,23 @@ public String getNoun() {
return Messages.ClaimBuildAction_Noun();
}

public Object readResolve() {
if (run != null && owner == null) {
owner = run;
}
return this;
}

@Override
String getUrl() {
return owner.getUrl();
}

@Override
protected Run getOwner() {
return owner;
}

@Override
public void onAttached(Run<?, ?> run) {
owner = run;
}

@Override
public void onLoad(Run<?, ?> run) {
owner = run;
}
}
@@ -56,7 +56,7 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace, @Nonn

Result runResult = build.getResult();
if (runResult != null && runResult.isWorseThan(Result.SUCCESS)) {
ClaimBuildAction action = new ClaimBuildAction(build);
ClaimBuildAction action = new ClaimBuildAction();
build.addAction(action);
build.save();

@@ -6,11 +6,9 @@
public class ClaimTestAction extends AbstractClaimBuildAction<Run> {

private String testObjectId;

private Data data;

ClaimTestAction(Data data, String testObjectId) {
super(data.getBuild());
this.data = data;
this.testObjectId = testObjectId;
}
@@ -35,4 +33,8 @@ String getUrl() {
return data.getUrl();
}

@Override
protected Run getOwner() {
return data.getBuild();
}
}

0 comments on commit 2515d77

Please sign in to comment.