'Jira REST API Time Tracking Null

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);
    }


Solution 1:[1]

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());
            }
        }

Solution 2:[2]

I have the same issue here, and I found other solution for this case, use:

issue.getField("timeoriginalestimate")

Solution 3:[3]

Similar to Mars option and the answer from Cosmin, this is (now) possible and ensures to get the full Timetracking object with the search query, you just need to explicitly request the "timetracking" field, but you also need to make sure to add the core fields such that the client can construct an Issue instance.

It goes like this (the list might also be a set, don't crucify me for syntax incorrectness, currently no IDE at hand).

 restClient.getSearchClient()
           .searchJql(q.getQuery(), q.getLimit(), q.getOffset(),
                       Lists.newArraylist(
                            "timetracking",
                            "summary",
                            "issuetype",
                            "created",
                            "updated",
                            "project",
                            "status"));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cosmin Oprea
Solution 2 Mars
Solution 3 Frank Hopkins