IssueService.validateUpdate can yield wrong result when used to update reporterId

Former user November 15, 2018

We are using Atlassian Crowd Server to manage users.
 * Some users have a User ID equal to the username
 * Others have a numeric ID

Example (all users coming from Crowd):
 * Reporter ID: ID11539, Username: TSmith
 * Reporter ID: aweickmann, Username: aweickmann
 * Reporter ID: pmiller, Username: PMiller

It would be interesting to know how these different patterns come into existence.

This is causing a problem with the IssueService.validateUpdate method, when used to update the reporter. We develop an add-on that copies issue data from one issue to another:
{code:java}
private void copyStandardFields(Issue source, Issue target, IssueInputParameters inputParameters) {
    inputParameters
            // user cannot be found in some constellations of unknown cause if we go with source.getReporterId
            .setReporterId(source.getReporter().getUsername());
}
...
issueService.validateUpdate(user, issue.getId(), inputParameters);
{code}
Problematic is:
 inputParametrs.setReporterId(source.getReporterId())

This works for users where the user id is equal to the username. But it fails in the numeric id case.

This is most likely due to the code in com.atlassian.jira.issue.fields.ReporterSystemField:
{code:java}
String returnedReporter = (String) fieldValuesHolder.get(getId());
...
// If the username has actually been given then check that the user actually exists
// Should we check that the user has CREATE ISSUE permission in the project?
ApplicationUser newReporter = UserUtils.getUser(returnedReporter);
{code}

UserUtils.getUser expects a username, not a user id. So it returns null in the numeric id case.
IssueInputParameters.setReporterId is a valid API call however, but you have to actually pass a username for it to work reliably.

0 answers

Suggest an answer

Log in or Sign up to answer