diff --git a/src/main/java/hudson/plugins/ec2/EC2Cloud.java b/src/main/java/hudson/plugins/ec2/EC2Cloud.java index a329cb6a4..4dcdc4974 100644 --- a/src/main/java/hudson/plugins/ec2/EC2Cloud.java +++ b/src/main/java/hudson/plugins/ec2/EC2Cloud.java @@ -415,6 +415,11 @@ public void addTemplate(SlaveTemplate newTemplate) throws Exception { throw new Exception( String.format("A SlaveTemplate with description %s already exists", newTemplateDescription)); } + if (newTemplate.parent != null) { + throw new Exception( + String.format("The new SlaveTemplate with description %s already has a parent", newTemplateDescription)); + } + newTemplate.parent = this; List templatesHolder = new ArrayList<>(templates); templatesHolder.add(newTemplate); templates = templatesHolder;