Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added test to catch null pointer error when a build has no labels. Fi…
…xed the null pointer error. This is a fix for [JENKINS-10467]
  • Loading branch information
beckje01 committed Jul 27, 2011
1 parent 86e0902 commit e38d523
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ec2/EC2Cloud.java
Expand Up @@ -124,7 +124,7 @@ public SlaveTemplate getTemplate(String ami) {
*/
public SlaveTemplate getTemplate(Label label) {
for (SlaveTemplate t : templates)
if(label.matches(t.getLabelSet()))
if(label == null || label.matches(t.getLabelSet()))
return t;
return null;
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/hudson/plugins/ec2/TemplateLabelsTest.java
Expand Up @@ -39,5 +39,14 @@ public void testLabelExpression() throws Exception{
assertEquals(false, ac.canProvision(Label.parseExpression("aaa || bbb")));
assertEquals(false, ac.canProvision(Label.parseExpression("aaa || bbb")));
}

public void testEmptyLabel() throws Exception{
SlaveTemplate temp = new SlaveTemplate("ami", "foo", "22", InstanceType.LARGE, "", "foo ami", "bar", "aaa", "10", "rrr", "fff", "-Xmx1g");
List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
templates.add(temp);
ac = new AmazonEC2Cloud(AwsRegion.US_EAST_1, "abc", "def", "ghi", "3", templates);

assertEquals(true, ac.canProvision(null));
}

}

0 comments on commit e38d523

Please sign in to comment.