Polarion WorkItem类的getter方法返回null

时间:2013-07-23 21:28:58

标签: java nullpointerexception

我正在尝试编写一个Java程序,该程序从Polarion获取工作记录信息并将其写入DAT文件以供以后使用。

我已经成功连接到我们的服务器并检索了WorkItem个对象,但是没有任何getter方法(除getUri()之外)似乎都有效,这会产生问题,因为我需要使用{ {1}}类的WorkItem方法来满足项目的要求。

我已经在我们的主要Polarion服务器和我们的'staging'服务器上尝试了所有类的getter方法,我们将其用作一种测试区域,例如我正在尝试编写的程序和我有完整的权限。

无论权限如何,我只查询我创建并分配给自己的一些虚拟工作项,因此我不应该有任何权限问题,因为我只是试图查看自己的工作项。

以下是该计划的代码:

getWorkRecords()

最重要的部分当然是我的代码中的package test; //stg= 10.4.1.50 //main= 10.4.1.10 import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.MalformedURLException; import java.rmi.RemoteException; import java.util.ArrayList; import javax.xml.rpc.ServiceException; import com.polarion.alm.ws.client.WebServiceFactory; import com.polarion.alm.ws.client.session.SessionWebService; import com.polarion.alm.ws.client.tracker.TrackerWebService; import com.polarion.alm.ws.client.types.tracker.WorkItem; import com.polarion.alm.ws.client.types.tracker.WorkRecord; public class WorkrecordImporter { private WebServiceFactory factory; private TrackerWebService trackerService; private SessionWebService sessionService; private WorkItem[] workItems; private ArrayList<WorkRecord> workRecords; private String password = //insertpasswordhere;//no peaking public WorkrecordImporter()throws ServiceException, IOException, ClassNotFoundException{ initializeFields();//initializes all of the Web Services and arrays //step one getWorkItems(); //readDATFile(); //step two getWorkRecords(); //$$$ printWorkRecords(); //$$$$$ writeDATFile(); } //you know what this does. public void printWorkRecords(){ for(int temp = 0; temp < workItems.length; temp++){ System.out.println(workItems[temp].getUri().toString()); } } public void writeDATFile() throws IOException{ ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("C:\\Users\\sweidenkopf\\workspace\\test\\filename.dat")); try { out.writeObject(workRecords); } finally { // Make sure to close the file when done out.close(); } } /** * This method sets up the WebServiceFactory at the specified URL. It then initializes the web services, logs in the * session service, and initializes the arrays. * @throws MalformedURLException * @throws ServiceException * @throws RemoteException */ public void initializeFields() throws MalformedURLException, ServiceException, RemoteException{ factory = new WebServiceFactory("//insert url here"); trackerService = factory.getTrackerService(); sessionService = factory.getSessionService(); sessionService.logIn("sweidenkopf", password); workRecords = new ArrayList<>(); } public void getWorkItems()throws MalformedURLException, ServiceException, RemoteException{ sessionService.beginTransaction(); workItems = trackerService.queryWorkItems("workRecords.user.id:sweidenkopf", null, null); sessionService.endTransaction(false); } public void getWorkRecords()throws MalformedURLException, ServiceException, RemoteException{ sessionService.beginTransaction(); for(int k = 0; k < workItems.length; k++) {System.out.println("This is working"); try{//not every work item has work records System.out.println(workItems[k].getWorkRecords()); WorkRecord[] temp; temp = workItems[k].getWorkRecords(); for(int x = 0; x < temp.length; x++){ System.out.println("This is working fine"); workRecords.add(temp[x]); } }catch(NullPointerException e){ System.out.println("I must regretfully inform you that I have grave news; your endeavors have not been successfull."); continue; } } System.out.println(workRecords.toString()); sessionService.endTransaction(false); } public void readDATFile() throws FileNotFoundException, IOException, ClassNotFoundException{ ObjectInputStream in = new ObjectInputStream(new FileInputStream("C:\\Users\\sweidenkopf\\workspace\\test\\filename.dat")); try{ Object temp = in.readObject(); workRecords = (ArrayList) temp; } finally{ in.close(); } } } 方法。如您所见,它包含我用于调试目的的语句getWorkRecords()。此语句返回System.out.println(workItems[k].getWorkRecords());,并且在该语句中替换时唯一不返回null的null方法是WorkItem。此外,该方法中的try-catch块总是捕获getUri(),因为NullPointerException循环包含for,temp是一个应该包含temp.length返回的变量方法。

总结这里的主要问题是我无法从getWorkRecords()getWorkRecords()类中的任何其他getter方法返回任何内容。这很令人费解,因为WorkItem方法正在成功执行,因为我的代码中的getUri()方法成功打印了我查询中所有printWorkRecords()个对象的URI。

以前是否有任何Polarion专家遇到过这个问题?有谁知道我做错了什么?我倾向于认为这是一个基于环境的错误。

1 个答案:

答案 0 :(得分:1)

对于它可能关心的人,我刚刚解决了这个问题。

如果你看一下我对queryWorkItems()方法的调用,你会注意到在查询参数之后我指定了两个空参数。第一个是一个参数,用于指定您希望如何对返回的工作项进行排序(目前这是无关紧要的),但第二个是一个名为String的{​​{1}}数组,用于指定fields中的哪一个您想要的{1}}字段与WorkItem本身一起返回。显然,如果你像我一样将其设置为WorkItems,则默认只返回URI。对于其他内容,例如author,workrecord和type,您必须将它们放在null数组中,并在调用方法时传递该数组。