Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-42969] UnsupportedOperationException from Computer.add…
…Action.
  • Loading branch information
jglick committed Mar 21, 2017
1 parent 4948d6c commit 8383577
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -1046,6 +1046,8 @@ public List<Action> getActions() {
return Collections.unmodifiableList(actions);
}

// TODO implement addAction, addOrReplaceAction, removeAction, removeActions, replaceActions

/**
* Gets the {@link Node} where this project was last built on.
*
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/model/Computer.java
Expand Up @@ -25,6 +25,7 @@
*/
package hudson.model;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher.ProcStarter;
Expand Down Expand Up @@ -268,6 +269,18 @@ public List<Action> getActions() {
return Collections.unmodifiableList(result);
}

@SuppressWarnings({"ConstantConditions","deprecation"})
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
@Override
public void addAction(@Nonnull Action a) {
if (a == null) {
throw new IllegalArgumentException("Action must be non-null");
}
super.getActions().add(a);
}

// TODO implement addOrReplaceAction, removeAction, removeActions, replaceActions

/**
* This is where the log from the remote agent goes.
* The method also creates a log directory if required.
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/model/labels/LabelAtom.java
Expand Up @@ -106,6 +106,8 @@ public List<Action> getActions() {
return Collections.unmodifiableList(actions);
}

// TODO implement addAction, addOrReplaceAction, removeAction, removeActions, replaceActions

protected void updateTransientActions() {
Vector<Action> ta = new Vector<Action>();

Expand Down
15 changes: 13 additions & 2 deletions test/src/test/java/hudson/model/ComputerTest.java
Expand Up @@ -31,7 +31,6 @@

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.xml.XmlPage;

import java.io.File;
Expand All @@ -40,7 +39,6 @@
import hudson.slaves.DumbSlave;
import hudson.slaves.OfflineCause;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -114,4 +112,17 @@ private void verifyOfflineCause(Computer computer) throws Exception {
assertThat(content, not(containsString("ApiTokenProperty")));
assertThat(content, not(containsString("apiToken")));
}

@Issue("JENKINS-42969")
@Test
public void addAction() throws Exception {
Computer c = j.createSlave().toComputer();
class A extends InvisibleAction {}
assertEquals(0, c.getActions(A.class).size());
c.addAction(new A());
assertEquals(1, c.getActions(A.class).size());
c.addAction(new A());
assertEquals(2, c.getActions(A.class).size());
}

}

0 comments on commit 8383577

Please sign in to comment.