From 3d2e93892490096416b16119522f4bf0bb23e711 Mon Sep 17 00:00:00 2001 From: John Shaw Date: Thu, 30 Jun 2016 10:40:52 +0100 Subject: [PATCH] Retries for null JSON content --- src/main/java/net/rcarz/jiraclient/Issue.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/rcarz/jiraclient/Issue.java b/src/main/java/net/rcarz/jiraclient/Issue.java index 1cb586ae..31b7f33c 100644 --- a/src/main/java/net/rcarz/jiraclient/Issue.java +++ b/src/main/java/net/rcarz/jiraclient/Issue.java @@ -632,22 +632,28 @@ private List getNextIssues() throws JiraException { } JSON result = null; + int tryCount = 0; + + while (result == null && tryCount++ <= 10) { + try { + URI searchUri = createSearchURI(restclient, jql, includedFields, + expandFields, maxResults, startAt); + result = restclient.get(searchUri); + } catch (Exception ex) { + throw new JiraException("Failed to search issues", ex); + } + } - try { - URI searchUri = createSearchURI(restclient, jql, includedFields, - expandFields, maxResults, startAt); - result = restclient.get(searchUri); - } catch (Exception ex) { - throw new JiraException("Failed to search issues", ex); + if (result == null) { + throw new JiraException("JSON payload is null"); } if (!(result instanceof JSONObject)) { throw new JiraException("JSON payload is malformed"); } - Map map = (Map) result; - + this.startAt = Field.getInteger(map.get("startAt")); this.maxResults = Field.getInteger(map.get("maxResults")); this.total = Field.getInteger(map.get("total"));