Version Picker (multiple versions) incorrectly persists data in JIRA change history

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Problem

The Version Picker (multiple versions) custom field incorrectly persists data in the change history table when making changes to issues. This can cause project imports to subsequently fail as the data's not in an expected state, causing errors similar to the following to appear in the logs:

2016-01-22 16:20:57,097 JiraTaskExectionThread-10 ERROR sysadmin 978x3742x1 z25doj 0:0:0:0:0:0:0:1 /secure/admin/ProjectImportSummary.jspa [c.a.jira.task.TaskManagerImpl] Task 'Importing project 'Project Name'.' failed.
java.lang.NumberFormatException: For input string: "[10150]"
	at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
	at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
	at java.lang.Double.parseDouble(Double.java:538)
	at java.lang.Double.<init>(Double.java:608)
	at com.atlassian.jira.imports.project.customfield.VersionCustomFieldImporter.getNonDecimalValue(VersionCustomFieldImporter.java:36)
	at com.atlassian.jira.imports.project.customfield.VersionCustomFieldImporter.getMappedImportValue(VersionCustomFieldImporter.java:26)
	at com.atlassian.jira.imports.project.transformer.ChangeItemTransformerImpl.mapCustomFieldIdList(ChangeItemTransformerImpl.java:73)
	at com.atlassian.jira.imports.project.transformer.ChangeItemTransformerImpl.transform(ChangeItemTransformerImpl.java:55)
	at com.atlassian.jira.imports.project.handler.ChangeItemPersisterHandler.handleEntity(ChangeItemPersisterHandler.java:54)
	at com.atlassian.jira.imports.project.handler.ChainedOfBizSaxHandler.endTopLevelElement(ChainedOfBizSaxHandler.java:219)
	at com.atlassian.jira.imports.project.handler.ChainedOfBizSaxHandler.endElement(ChainedOfBizSaxHandler.java:167)
	at com.atlassian.jira.imports.project.handler.ChainedOfBizSaxHandler.endElement(ChainedOfBizSaxHandler.java:134)
	at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
	at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at com.atlassian.security.xml.RestrictedXMLReader.parse(RestrictedXMLReader.java:103)
	at com.atlassian.jira.imports.xml.DefaultBackupXmlParser$XmlParser.parseXml(DefaultBackupXmlParser.java:115)
	at com.atlassian.jira.imports.xml.DefaultBackupXmlParser.parse(DefaultBackupXmlParser.java:64)
	at com.atlassian.jira.imports.xml.DefaultBackupXmlParser.parseXml(DefaultBackupXmlParser.java:52)
	at com.atlassian.jira.imports.xml.DefaultBackupXmlParser.parseOfBizBackupXml(DefaultBackupXmlParser.java:41)
	at com.atlassian.jira.imports.project.DefaultProjectImportManager.importChangeItemEntities(DefaultProjectImportManager.java:1113)
	at com.atlassian.jira.imports.project.DefaultProjectImportManager.doImport(DefaultProjectImportManager.java:659)
	at com.atlassian.jira.bc.imports.project.DefaultProjectImportService.doImport(DefaultProjectImportService.java:416)
	at com.atlassian.jira.web.action.admin.importer.project.ProjectImportSummary$ProjectImportCallable.call(ProjectImportSummary.java:285)
	at com.atlassian.jira.web.action.admin.importer.project.ProjectImportSummary$ProjectImportCallable.call(ProjectImportSummary.java:236)
	at com.atlassian.jira.task.TaskManagerImpl$TaskCallableDecorator.call(TaskManagerImpl.java:458)
	at com.atlassian.jira.task.TaskManagerImpl$TaskCallableDecorator.call(TaskManagerImpl.java:426)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at com.atlassian.jira.task.ForkedThreadExecutor$ForkedRunnableDecorator.run(ForkedThreadExecutor.java:216)
	at java.lang.Thread.run(Thread.java:745)

Cause

The data is persisted incorrectly in the backup with square brackets, which can cause project imports to fail. Note that the full XML backup and restore functionality will still continue to work as expected.

Workaround

It is important to not perform this changes directly on a production instance (Except if the source instance will no longer be used after the Project Import). Instead, we recommend setting up a staging server using an XML backup from the source instance, perform the changes on the staging server and then generate a new backup from that staging server to perform Project Import.

If needing to project import, the database can be edited with the below steps. These were verified on PostgreSQL and the syntax may vary for different DBMS.

  1. Backup JIRA.
  2. Stop JIRA.
  3. Execute the below SQL to identify the affected fields:

    SELECT * FROM changeitem WHERE oldvalue LIKE '[%]' OR newvalue LIKE '[%]';

    (warning) The above query was tested on PostgreSQL and the syntax may vary for different DBMS.

  4. Execute the below SQL to remove the brackets:

    PostgreSQL

    update changeitem set oldvalue = trim(both '[]' from oldvalue), newvalue = trim(both '[]' from newvalue) where field = '<affected field name>';

    MySQL

    UPDATE changeitem SET NEWVALUE = replace(replace(NEWVALUE,']',''),'[','') where field='<affected field name>' AND NEWVALUE like '[%]';
    UPDATE changeitem SET OLDVALUE = replace(replace(OLDVALUE,']',''),'[','') where field='<affected field name>' AND OLDVALUE like '[%]';

    SQL Server

    UPDATE changeitem SET NEWVALUE = replace(CONVERT(VARCHAR(MAX), replace(CONVERT(VARCHAR(MAX), NEWVALUE),']','')),'[','')
    where field='<affected field name>' AND NEWVALUE like '[[]%]';
    UPDATE changeitem SET OLDVALUE = replace(CONVERT(VARCHAR(MAX), replace(CONVERT(VARCHAR(MAX), OLDVALUE),']','')),'[','')
    where field='<affected field name>' AND OLDVALUE like '[[]%]';

    Oracle

    update changeitem set oldvalue = trim('[' from oldvalue), newvalue = trim ('[' from newvalue) where field = '<affected field name>';
    update changeitem set oldvalue = trim(']' from oldvalue), newvalue = trim (']' from newvalue) where field = '<affected field name>';
  5. In some cases, this may cause empty values to be present. We can fix this with the below:

    PostgreSQL

    UPDATE changeitem SET oldvalue = NULL WHERE oldvalue = '' AND field = <affected field name>;
    UPDATE changeitem SET newvalue = NULL WHERE newvalue = '' AND field = <affected field name>;
  6. Start JIRA

  7. Generate an XML backup and use that for importing into the target instance.


Resolution

Bug reported in  JRASERVER-59681 - Getting issue details... STATUS


Last modified on Sep 9, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.