Jira Cloud REST API getting an error on Promise<Issue>.claim()

Robinwchahal February 18, 2020

I have a Java application that is using jira-rest-java-client-core version 5.1.6 to create tickets in Jira Cloud and add comments to these tickets.

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.1.6</version>
</dependency>

 Everything was working, and there were no changes to the code.  On Feb. 14, 2020 we started getting exceptions.

Caused by: org.codehaus.jettison.json.JSONException: JSONObject["name"] not found.
at org.codehaus.jettison.json.JSONObject.get(JSONObject.java:360)
at org.codehaus.jettison.json.JSONObject.getString(JSONObject.java:487)
at com.atlassian.jira.rest.client.internal.json.JsonParseUtil.parseBasicUser(JsonParseUtil.java:192)
at com.atlassian.jira.rest.client.internal.json.UserJsonParser.parse(UserJsonParser.java:34)
at com.atlassian.jira.rest.client.internal.json.UserJsonParser.parse(UserJsonParser.java:31)
at com.atlassian.jira.rest.client.internal.json.IssueJsonParser.getOptionalNestedField(IssueJsonParser.java:300)
at com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parse(IssueJsonParser.java:235)
at com.atlassian.jira.rest.client.internal.json.IssueJsonParser.parse(IssueJsonParser.java:88)
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$1.handle(AbstractAsynchronousRestClient.java:148)
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:189)
... 15 more

I know Atlassian has been making changes to remove user names from the API.  This makes total sense.  The thing is, my code isn't trying to get any user information.

My code that is failing is:

public void createComment(Message message, String username) {
IssueRestClient issueRestClient = jiraRestClient.getIssueClient();
URI issueUri = issueRestClient.getIssue(message.getChat().getJiraIssueKey()).claim().getCommentsUri();
issueRestClient.addComment(issueUri, commentFactory.create(message, username)).claim();
}

 Digging into this more, the problem seems to be in the Jira class 

com.atlassian.jira.rest.client.internal.json.JsonParseUtil on line 192
@Nullable
public static BasicUser parseBasicUser(@Nullable JSONObject json) throws JSONException {
if (json == null) {
return null;
} else {
String username = json.getString("name");
if (!json.has("self") && "Anonymous".equals(username)) {
return null;
} else {
URI selfUri = optSelfUri(json, BasicUser.INCOMPLETE_URI);
return new BasicUser(selfUri, username, json.optString("displayName", (String)null));
}
}
}

Is there an updated version of the jira-rest-java-client-core library?
Is this a Jira bug or something else?

Is there a workaround?

There is a similar issue for this but in that issue, they are actually trying to get the user name.  I don't care about the username.
https://community.atlassian.com/t5/Jira-questions/JIRA-REST-API-missing-parameters/qaq-p/1302944#U1303392

4 answers

2 votes
Narayanan Srinivasan February 18, 2020

It's the same problem. In order to parse the issue, it also needs to parse the names in it, like reporter, assignee etc. It can't because "name" isn't optional. The workaround is in the issue you linked, and the better solution is to not use JRJC for Jira cloud because they've stated here -- https://ecosystem.atlassian.net/wiki/spaces/JRJC/overview that JRJC isn't compatible with Jira Cloud.

Robinwchahal February 18, 2020

Supporting Jira Cloud must be nearly impossible, as it's supporting a moving target with a static library.

That said, I'd be surprised if this issue isn't effecting Jira Server.

There was a change to the Jira back end, to stop returning "name".

(https://community.developer.atlassian.com/t/announcement-reminder-on-removal-of-user-names/34111?_ga=2.149019254.159990438.1581955730-576781502.1579187949)

And, the Jira code in JsonParseUtil is expecting a "name" value.

1 vote
fellipe.gurgel February 18, 2020

I'm facing the same problem. Did you fix yours, @Robinwchahal?

Robinwchahal February 19, 2020

Hi @fellipe.gurgel , no fix yet ....

0 votes
Thierry February 19, 2020

Similar problem in the .Net Atlassian SDK, in their own source code it tries to access 

json[this._propertyName]

where _propertyName is set to "name" and we get a NullReferenceException. Changing this to "displayName" makes my app work again.

I've asked my question here with a lot more details: https://community.atlassian.com/t5/Jira-questions/SDK-name-vs-displayName-userPicker-NullReferenceException-in/qaq-p/1303712

0 votes
Marcel Richter February 19, 2020

Same problem here, I guess an updated version of JRJC is required.

 

Simple call to project client fails. I don't need the actual value:

client.projectClient.getProject(projectName).claim()

 

Suggest an answer

Log in or Sign up to answer