Skip to content

Commit

Permalink
[FIXED JENKINS-39647] getDefaultParameterValue should not fail
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedam committed Jan 15, 2017
1 parent 2675132 commit 535d9d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Expand Up @@ -394,7 +394,11 @@ protected ParameterValue createValueCommon(StringParameterValue value)
if(!isEditable() && !getChoiceList().contains(value.value))
{
// Something strange!: Not editable and specified a value not in the choices.
throw new IllegalArgumentException("Illegal choice: " + value.value);
throw new IllegalArgumentException(String.format(
"Illegal choice '%s' in parameter '%s&",
value.value,
value.getName()
));
}
return value;
}
Expand Down Expand Up @@ -447,7 +451,12 @@ public ParameterValue getDefaultParameterValue()
String defaultChoice = (p != null)?p.getDefaultChoice():null;
if(defaultChoice != null)
{
return createValue(defaultChoice);
try {
return createValue(defaultChoice);
} catch (IllegalArgumentException e) {
LOGGER.log(Level.WARNING, "Illegal choice for the default value. Ignore and use the value in the top of the list instead.", e);
// pass through
}
}

List<String> choiceList = getChoiceList();
Expand Down
Expand Up @@ -613,6 +613,7 @@ public void testGetDefaultParameterValue() throws Exception
}

// non-editable, not in choice
// The value on the top should be used.
{
ChoiceListProvider provider = new MockChoiceListProvider(Arrays.asList("value1", "value2", "value3"), "value4");
ExtensibleChoiceParameterDefinition def = new ExtensibleChoiceParameterDefinition(
Expand All @@ -627,14 +628,8 @@ public void testGetDefaultParameterValue() throws Exception
job.getBuildersList().add(ceb);
job.save();

try{
job.scheduleBuild2(job.getQuietPeriod()).get();
assertTrue("not reachable", false);
}
catch(IllegalArgumentException e)
{
assertTrue("non-editable, not in choice", true);
}
j.assertBuildStatusSuccess(job.scheduleBuild2(0));
assertEquals("value1", ceb.getEnvVars().get("test"));
}
}

Expand Down Expand Up @@ -994,6 +989,7 @@ public void testGetDefaultParameterValue_SpecifiedDefaultChoice()
}

// Non-editable, not in choices
// The value on the top should be used.
{
String defaultChoice = "value4";
ChoiceListProvider provider = new MockChoiceListProvider(Arrays.asList("value1", "value2", "value3"), defaultChoice);
Expand All @@ -1003,15 +999,7 @@ public void testGetDefaultParameterValue_SpecifiedDefaultChoice()
false,
description
);
try
{
assertEquals("Non-Editable, not in choices", new StringParameterValue(name, defaultChoice, description), target.getDefaultParameterValue());
assertTrue("Not reachable", false);
}
catch(IllegalArgumentException e)
{
assertTrue("Non-Editable, not in choices", true);
}
assertEquals(new StringParameterValue(name, "value1", description), target.getDefaultParameterValue());
}

// no choice is provided and non-editable. returns null.
Expand Down

1 comment on commit 535d9d7

@vickikozel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
i get Illegal choice 'Parameter_Name' in parameter 'Parameter_Value' exception when passing a system groovy generated choice from a controller job to a downstream job that has the same exactly the same script generating the same list. Controller job invokes downstream with a "Current Build Parameters" . Is this intended?

Please sign in to comment.