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