Skip to content
Permalink
Browse files

[FIXED JENKINS-41209] Be more defensive of nulls in accessing the act…

…ion field
  • Loading branch information
stephenc committed Jan 19, 2017
1 parent d13aeba commit c1fc325e794935defea0a552007099abde79d65f
Showing with 7 additions and 18 deletions.
  1. +7 −18 src/main/java/jenkins/branch/Branch.java
@@ -82,7 +82,7 @@
* representation is simpler.
* @since 2.0
*/
private List<Action> actions = new ArrayList<>();
private List<Action> actions;

/**
* Constructs a branch instance.
@@ -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<>();
}

/**
@@ -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;
}
@@ -220,7 +221,7 @@ public boolean hasProperty(Class<? extends BranchProperty> clazz) {
*/
@NonNull
public List<Action> getActions() {
return Collections.unmodifiableList(actions);
return actions == null ? Collections.<Action>emptyList() : Collections.unmodifiableList(actions);
}

/**
@@ -240,6 +241,9 @@ public boolean hasProperty(Class<? extends BranchProperty> clazz) {
*/
@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);
@@ -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}
*/

0 comments on commit c1fc325

Please sign in to comment.
You can’t perform that action at this time.