JRJC throwing JSONException sporadically

It appears like on few REST calls (createIssue() for example), JRJC will receive an empty string for a result and will throw the exception below. Calling the REST method again works though, so I have to make the following hack:

int tries = 0;                                           
do {                                                     
    try {                                                
        basicIssue = issueClient.createIssue(in).claim();
        tries = 1000000;                                 
    } catch (Exception e) {                              
        tries++;                                         
        System.err.println("Failed creating issue!");    
        e.printStackTrace();                             
    }                                                    
} while (tries <= 3);

com.atlassian.jira.rest.client.api.RestClientException: org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of 
	at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:181)
	at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:175)
	at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:62)
	at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:12)
	at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:285)
	at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:162)
	at com.google.common.util.concurrent.Futures$7.run(Futures.java:1072)
	at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
	at com.google.common.util.concurrent.ExecutionList$RunnableExecutorPair.execute(ExecutionList.java:161)
	at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:146)
	at com.google.common.util.concurrent.AbstractFuture.done(AbstractFuture.java:235)
	at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:172)
	at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
	at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:285)
	at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:162)
	at com.google.common.util.concurrent.Futures$7.run(Futures.java:1072)
	at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
	at com.google.common.util.concurrent.ExecutionList$RunnableExecutorPair.execute(ExecutionList.java:161)
	at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:146)
	at com.google.common.util.concurrent.AbstractFuture.done(AbstractFuture.java:235)
	at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:172)
	at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
	at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$1$1.run(SettableFuturePromiseHttpPromiseAsyncClient.java:46)
	at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable$1.run(SettableFuturePromiseHttpPromiseAsyncClient.java:197)
	at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient.runInContext(SettableFuturePromiseHttpPromiseAsyncClient.java:90)
	at com.atlassian.httpclient.apache.httpcomponents.SettableFuturePromiseHttpPromiseAsyncClient$ThreadLocalDelegateRunnable.run(SettableFuturePromiseHttpPromiseAsyncClient.java:192)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)
Caused by: org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of 
	at org.codehaus.jettison.json.JSONTokener.syntaxError(JSONTokener.java:439)
	at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:169)
	at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:266)
	at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$1.handle(AbstractAsynchronousRestClient.java:138)
	at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:179)
	... 28 more

3 answers

Using JRJC 2.0.0-m8 and 2.0.0-m9. same behavior

It appears like JRJC 2.0.0 is too immature. Ported the code back to JRJC 1.0.0 and it no weird async things happen.

I've replied in https://ecosystem.atlassian.net/browse/JRJC-146 - we need more details to track this issue. The 2.0.0-m16 should be quite stable (not many changes are planed for 2.0 release).

P.S. Next time please add jira-rest-java-client tag, so we'll get notified about new question related to JRJC.

Hi Yarin,

Also you may need to report this to https://ecosystem.atlassian.net/browse/JRJC so our developers can take a look at it.

Cheers,

Omar

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

232 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you