Skip to content

Commit

Permalink
[FIXED JENKINS-41209] Be more defensive of nulls in accessing the act…
Browse files Browse the repository at this point in the history
…ion field
  • Loading branch information
stephenc committed Jan 19, 2017
1 parent d13aeba commit c1fc325
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/main/java/jenkins/branch/Branch.java
Expand Up @@ -82,7 +82,7 @@ public class Branch {
* representation is simpler.
* @since 2.0
*/
private List<Action> actions = new ArrayList<>();
private List<Action> actions;

/**
* Constructs a branch instance.
Expand All @@ -97,6 +97,7 @@ public Branch(String sourceId, SCMHead head, SCM scm, List<? extends BranchPrope
this.head = head;
this.scm = scm;
this.properties.addAll(properties);
this.actions = new ArrayList<>();
}

/**
Expand All @@ -122,7 +123,7 @@ private Branch(String id, SCM scm, Branch b) {
*/
private Object readResolve() throws ObjectStreamException {
if (actions == null) {
return new Branch(sourceId, head, scm, properties);
actions = new ArrayList<>();
}
return this;
}
Expand Down Expand Up @@ -220,7 +221,7 @@ public List<BranchProperty> getProperties() {
*/
@NonNull
public List<Action> getActions() {
return Collections.unmodifiableList(actions);
return actions == null ? Collections.<Action>emptyList() : Collections.unmodifiableList(actions);
}

/**
Expand All @@ -240,6 +241,9 @@ public List<Action> getActions() {
*/
@CheckForNull
public <T extends Action> T getAction(Class<T> clazz) {
if (actions == null) {
return null;
}
for (Action p : actions) {
if (clazz.isInstance(p)) {
return clazz.cast(p);
Expand Down Expand Up @@ -315,21 +319,6 @@ public Dead(Branch b) {
super(NullSCMSource.ID, new NullSCM(), b);
}

/**
* Ensure actions is never null.
*
* @return the deserialized object.
* @throws ObjectStreamException if things go wrong.
*/
@SuppressWarnings("ConstantConditions")
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
private Object readResolve() throws ObjectStreamException {
if (getActions() == null) {
return new Branch.Dead(getHead(), getProperties());
}
return this;
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit c1fc325

Please sign in to comment.