Details
-
Bug
-
Resolution: Fixed
-
Medium
-
2.6.1 Pro, 2.6.1 Enterprise
-
Linux jiradev1.ad.newisys.com 2.4.22-1.2197.nptlsmp #1 SMP Thu Jul 1 15:07:03 EDT 2004 i686 athlon i386 GNU/Linux
jira Enterprise 2.6.1
-
2.06
-
Description
executing the following jelly script results in a new custom field of type select with only one select option - the last value added via the AddCustomFieldSelectValue tag.
<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.JiraTagLib">
<jira:CreateCustomField fieldType="select" fieldScope="global" fieldName="jellyTest2">
<jira:AddCustomFieldSelectValue value="No" />
<jira:AddCustomFieldSelectValue value="Yes" />
<jira:AddCustomFieldSelectValue value="aaa" />
<jira:AddCustomFieldSelectValue value="bbb" />
<jira:AddCustomFieldSelectValue value="ccc" />
</jira:CreateCustomField>
</JiraJelly>
...
I believe the jira code is wrong (and possible could create a memory fault):
public class CreateCustomField extends UserAwareActionTagSupport
...
public void addSelectValue(String value)
{
String[] values = (String[]) getProperties().get(KEY_SELECT_VALUES);
if (values == null)
else
{
// Copy into new String[]
String[] newValues = new String[values.length];
for (int i = 0; i < values.length; i++)
values = newValues;
}
values[values.length - 1] = value;
getProperties().put(KEY_SELECT_VALUES, values);
}
When you add the second value to the values list it adds it to array index 0, overwriting the first value. When you add the initial value to the values list it writes it to index -1, creating a potential memory fault.
I modified the code as follows:
public void addSelectValue(String value)
{
String[] values = (String[]) getProperties().get(KEY_SELECT_VALUES);
if (values == null)
{ values = new String[1]; // Added 21JUL2004 WAC wcrighton@wacconsulting.com values[0] = value; }
else
{
// Copy into new String[]
// Modified 21JUL2004 WAC wcrighton@wacconsulting.com
String[] newValues = new String[values.length+1];
for (int i = 0; i < values.length; i++)
{ newValues[i] = values[i]; }
// Removed 21JUL2004 WAC wcrighton@wacconsulting.com
//values = newValues;
// Added 21JUL2004 WAC wcrighton@wacconsulting.com
newValues[values.length] = value;
values = newValues;
}
// Removed 21JUL2004 WAC wcrighton@wacconsulting.com
//values[values.length - 1] = value;
getProperties().put(KEY_SELECT_VALUES, values);
}
And all the values are added and appear as desired. Please let me know if you agree.