当我尝试跟踪问题的时间时,我的下面的代码让我得到一个空指针异常,即使问题有时间跟踪,我正在使用这个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);
}
答案 0 :(得分:2)
我通过以下方式解决了这个问题:
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'是我想要的字段,但是如果你真的想要那个对象TimeTracking你必须提出另一个服务器请求将会持续一些宝贵的时间,我不会推荐这个,但我会展示代码:
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());
}
}
答案 1 :(得分:0)
我在这里遇到相同的问题,并且找到了这种情况的其他解决方案,请使用:
issue.getField("timeoriginalestimate")