Reindexing JIRA causes a Nullpointer Error

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

The following appears in the atlassian-jira.log:

Caused by: java.lang.NullPointerException
at com.atlassian.greenhopper.manager.issuelink.EpicLinkManagerImpl.getEpic(EpicLinkManagerImpl.java:101)
at com.atlassian.greenhopper.customfield.epiclink.EpicLinkCFType.getValueFromIssue(EpicLinkCFType.java:77)
at com.atlassian.jira.issue.fields.CustomFieldImpl.getValue(CustomFieldImpl.java:381)
at com.atlassian.greenhopper.customfield.epiclink.EpicLinkCustomFieldIndexer.addIndex(EpicLinkCustomFieldIndexer.java:41)

Or you might see:

java.lang.NullPointerException
	at com.atlassian.jira.issue.index.indexers.impl.SubTaskIndexer.addIndex(SubTaskIndexer.java:47)
	at com.atlassian.jira.issue.index.indexers.FieldIndexer.addIndex(FieldIndexer.java:114)
	at com.atlassian.jira.issue.index.indexers.FieldIndexerWithStats.addIndex(FieldIndexerWithStats.java:57)
	at com.atlassian.jira.issue.index.DefaultIssueDocumentFactory$Builder.add(DefaultIssueDocumentFactory.java:331)
	at com.atlassian.jira.issue.index.DefaultIssueDocumentFactory$Builder.addAll(DefaultIssueDocumentFactory.java:307)
	at com.atlassian.jira.issue.index.DefaultIssueDocumentFactory.getDocument(DefaultIssueDocumentFactory.java:127)
	at com.atlassian.jira.issue.index.DefaultIssueDocumentFactory.lambda$createDocuments$1(DefaultIssueDocumentFactory.java:112)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)


Cause

The cause may vary but a few known causes are:

  • Re-indexing following the addition of a 'custom field' when a user is using GreenHopper.
  • If two issues are somehow linked with each other using an issuelinktype which doesn't exist anymore.
  • When an Epic link source is not an Epic, although this is less common.

Resolution

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

1. Run the integrity checker: Using the Database Integrity Checker

2. Try to Re-index JIRA again.  

3. If re-indexing still fails, then continue on with the next steps. Please run the following queries on the Jira DB:

3.1 To check if an issue source doesn't exist anymore:

SELECT * FROM issuelink WHERE SOURCE NOT IN (SELECT ID FROM jiraissue);

3.2 To check if an issue type doesn't exist anymore:

SELECT * FROM issuelink WHERE linktype NOT IN (SELECT id FROM issuelinktype);

3.3 To check if an Epic link source is not an Epic:

SELECT *
FROM issuelink l
JOIN issuelinktype ilt on ilt.id=l.linktype
JOIN jiraissue i on l.source=i.id
JOIN issuetype it on it.id=i.issuetype
WHERE ilt.linkname='Epic-Story Link'
AND it.pname<>'Epic'


4. If any of the previous queries returns a result, then:

  • Shutdown Jira
  • Execute the following query on the DB
    • If the first query (3.1) returns results:

DELETE FROM issuelink WHERE SOURCE NOT IN (SELECT ID FROM jiraissue);
    • If the second query (3.2) returns results:

DELETE FROM issuelink WHERE linktype NOT IN (SELECT id FROM issuelinktype);
    • If the third query (3.3) returns results
DELETE FROM issuelink WHERE id in (
SELECT l.id
FROM issuelink l
JOIN issuelinktype ilt on ilt.id=l.linktype
JOIN jiraissue i on l.source=i.id
JOIN issuetype it on it.id=i.issuetype
WHERE ilt.linkname='Epic-Story Link'
AND it.pname<>'Epic' )


5. If re-indexing still fails, then:

  • Run the command
select * from jiraissue where issuetype is null;
  • If this returns any rows, then please find an appropriate issuetype for the issue key returned in the previous query. For this we run: 
select * from issuetype;
  • Once the id of the issue type if identified, run the below sql:
update jiraissue set issuetype = <<id found from the above query>> where id = <<jira issue id found in the first query>>
Last modified on Mar 31, 2024

Was this helpful?

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