Skip to content
Permalink
Browse files
[FIXED JENKINS-39647] getDefaultParameterValue should not fail
  • Loading branch information
ikedam committed Jan 15, 2017
1 parent 2675132 commit 535d9d79337948fbbbefabb9189aad2d67cdd53d
@@ -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;
}
@@ -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();
@@ -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(
@@ -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"));
}
}

@@ -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);
@@ -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.

1 comment on commit 535d9d7

@vickikozel

This comment has been minimized.

Copy link

@vickikozel vickikozel commented on 535d9d7 Jun 8, 2017

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.