My below code is getting me a null pointer exception when I try to get time tracking for my issues , even if the issue have time tracking , I'm using this api:
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-api</artifactId>
<version>2.0.0-m19</version>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>2.0.0-m19</version>
</dependency>
//
for (JiraFixVersion jiraFixVersion : listJiraFixVersionsProject) {
Iterator<Issue> issues = JiraClientManager.getInstance().getSearchResultSet("project='" + jiraProject.getProjectName()
+ "' AND fixVersion =" + "'" + jiraFixVersion.getName() + "'").iterator();
Integer sumEstimatedTimeHours = 0;
while (issues.hasNext()) {
Issue issue = issues.next();
Integer estimatedTime =0;
try {
//Here is NullPointerException
TimeTracking timeTracking = issue.getTimeTracking();
estimatedTime = timeTracking.getOriginalEstimateMinutes();
System.out.println("ok "+issue.getKey());
}catch(NullPointerException e){
System.out.println("Time Tracking null "+ issue.getKey());
}
sumEstimatedTimeHours += estimatedTime;
}
returnMap.put(jiraFixVersion, sumEstimatedTimeHours);
}
I solved this through getting my field with :
for (JiraFixVersion jiraFixVersion : listJiraFixVersionsProject) {
Iterator<Issue> issues = JiraClientManager.getInstance().getSearchResultSet("project='" + jiraProject.getProjectName() + "' AND fixVersion =" + "'" + jiraFixVersion.getName() + "'" + " AND cf[10002] !=null").iterator();
Double sumStoryPoints = 0.0;
while (issues.hasNext()) {
Issue issue = issues.next();
String storyPoints = issue.getField("customfield_10002").getValue().toString();
Double storyPointIssue = Double.parseDouble(storyPoints);
sumStoryPoints += storyPointIssue;
}
returnMap.put(jiraFixVersion, sumStoryPoints);
}
'customfield_1002' is the field that I wanted , but if you really want that object TimeTracking you have to make another server request wich will last some precious time , I will not recommend that , but I will show the code :
while (issues.hasNext()) {
Issue issue = issues.next();
try {
Issue claim = JiraClientManager.getInstance().getRestClient().getIssueClient().getIssue(issue.getKey()).claim();
TimeTracking timeTracking = claim.getTimeTracking();
Integer estimatedTimeSeconds =(Integer) issue.getField("timeoriginalestimate").getValue();
Double estimatedTimeHours = (estimatedTimeSeconds.doubleValue())/3600;
System.out.println(estimatedTimeHours+" "+issue.getKey());
sumEstimatedTimeHours += estimatedTimeHours;
}catch(NullPointerException e){
System.out.println("Time Tracking null "+ issue.getKey());
}
}