Exception: key should not be null!

Problem

Error  "key should not be null" appears in the log files and emails are not processed by Email This Issue. 

Typical stacktrace in the logs.

2016-10-31 12:31:00,617 atlassian-scheduler-quartz1.clustered_Worker-3 ERROR anonymous IT-Helpdesk [atlassian.mail.incoming.mailfetcherservice] IT-Helpdesk[13000]: Exception: key should not be null!
com.atlassian.jira.util.dbc.Assertions$NullArgumentException: key should not be null!
at com.atlassian.jira.util.dbc.Assertions.notNull(Assertions.java:29)
at com.atlassian.jira.user.DelegatingApplicationUser.<init>(DelegatingApplicationUser.java:20)
at com.atlassian.jira.user.util.DefaultUserManager.getAllApplicationUsers(DefaultUserManager.java:105)
at com.metainf.jira.plugin.emailissue.handler.EmailThisIssueMailHandler.filterForUsers(EmailThisIssueMailHandler.java:786)
at com.metainf.jira.plugin.emailissue.handler.EmailThisIssueMailHandler.handleMessage(EmailThisIssueMailHandler.java:179)

The problem occurs because some of the user accounts do not have a corresponding user key. However user key is mandatory in JIRA.

Solution

JIRA Caches user keys to user names. To find  defect user accounts execute this SQL query:

SELECT
    lower_user_name
FROM
    cwd_user
WHERE
    lower_user_name NOT IN (
        SELECT lower_user_name FROM app_user
);


If the query returns a result, that means those users were not created/migrated correctly and do not have an entry in app_user.

Before running the query, read through a related KB article: https://confluence.atlassian.com/jirakb/jira-login-fails-with-user-exists-but-has-no-unique-key-mapping-373261121.html