Searching for Jira issue by custom field value results in NullPointerException

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

When performing a search including a custom field with null value or if there are invalid entries in the customfieldoption table, JIRA will throw out the following error:

java.lang.NullPointerException
at com.atlassian.jira.issue.customfields.manager.DefaultOptionsManager.findByOptionValue(DefaultOptionsManager.java:164)
at com.atlassian.jira.issue.customfields.manager.CachedOptionsManager.findByOptionValue(CachedOptionsManager.java:95)
at com.atlassian.jira.jql.util.JqlSelectOptionsUtil.getOptionFromString(JqlSelectOptionsUtil.java:208)
at com.atlassian.jira.jql.util.JqlSelectOptionsUtil.getOptions(JqlSelectOptionsUtil.java:135)

Cause

Scenario 1

There is a null value in the customfieldoption table. When a search is performed, it will search for all the custom field value options, so, if any of the values is null it will throw out an error.

Scenario 2

There are entries in the customfieldoption table that do not correspond to any custom field.

Root cause

It is yet unclear how custom field options may become unassociated from their fields, or end up with null values.

It is speculated that instability on the database connection or a Jira ungraceful termination while an operation on them was taking place could eventually lead to these residues on the database.
Alternatively, they could also be a result of direct database manipulation or database type conversion errors.

However, it was not possible to audit their origin any further.


Resolution

After performing the steps below, if the issue persists after the reboot, ensure to run a Full re-index of the instance and verify.

Scenario 1 - UI

  1. Perform the following query in JIRA's database, then take note of the custom fields returned;

    SELECT 
    	c.cfname AS "Custom Field",
    	o.customvalue AS "Value"
    FROM
    	customfield c
    	JOIN customfieldoption o ON c.id = o.customfield 
    WHERE
    	customvalue IS NULL;
  2. Go to AdministrationIssues > Custom Field;
  3. Click Configure on the right of each custom field returned by the query above;
  4. Delete any null option;

Scenario 1 - Database

Always back up your data before performing any modification to the database. If possible, try your modifications on a test server.

  1. If the above fails to resolve the issue, proceed with the deletion of the null value directly on the database. For that, use the following query:

    DELETE FROM customfieldoption WHERE customvalue is null;
  2. Restart JIRA for changes to take effect.


Scenario 2

  1. Perform the following query on JIRA's database to check if there are invalid entries on the customfieldoption table;

    SELECT
    	customfield
    FROM
    	customfieldoption
    WHERE
    	customfield NOT IN (
    		SELECT 
    			id
    		FROM
    			customfield
    		);
  2. If the above query returns any result, run the query below;

    DELETE
    FROM
    	customfieldoption
    WHERE
    	customfield NOT IN (
    		SELECT
    			id
    		FROM
    			customfield
    		);
  3. Restart JIRA for changes to take effect.

Last modified on Jan 11, 2023

Was this helpful?

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