Error on call of IFolder.getPath method (XI R2 / java)

Hello
when I try to get the path of a folder object in my XI R2 repository, I have a “null pointer exception error”.
Here is my code :

    boInfoObjects = boInfoStore.query("SELECT * FROM CI_INFOOBJECTS WHERE SI_KIND= 'Folder'");


    // work on the first answer :

    IFolder folder = (Ifolder) boInfoObjects.get(0);

    String title = folder.getTitle();  // OK
    String path  = folder.getPath()[0]; // KO  : null pointer exception

Is there something wrong in this code ?

Thanks for your help


franzy (BOB member since 2007-02-13)

The problem lies in the return value for the getPath() method. If the folder is a top-level folder, e.g. it is one level below Public Folders, the method returns a null value. getPath() does not return the name of the folder that is executing the method so its result is an empty array. For example, let’s assume you have 2 folders:

top folder which is a child of Public Folders
child folder which is a child of Public Folders/parent folder/

For the first folder, top folder, Null is returned. For the second folder, parent folder is returned.

Try this instead:


String title = folder.getTitle();
String path = "";
try{
     path = folder.getPath()[0];
}
catch(NullPointerException e){
     path = title;
}

BoB LoblaW :us: (BOB member since 2007-10-23)

Nice answer, many thanks my bff jill.

Meanwhile, I also discovered another possible cause of pointer exception :

it seems that if we don’t select some columns in the query, the object will not know their values :

boInfoObjects = boInfoStore.query("SELECT SI_ID FROM CI_INFOOBJECTS WHERE SI_KIND = "Webi");
boInfoObject = (IInfoObject) boInfoObjects.get(0);

=> The boInfoObject will know (quite ?) only the SI_ID value.
Well, it seems logical, after all.

But, in the same idea, if we get an object with the getParent() method, it will also have some items unfilled, unless we complete them by querying again the infostore with the parent Id retrieved.


franzy (BOB member since 2007-02-13)

franzy, you are correct; you must include properties you want to work with in your query or a null exception will be thrown. The same is true if you call getParent() with no arguments. However, the following call is equivalent to retrieving the parent with a Select * from… where si_id =


iObject.getParent(IInfoObject.PropertySet.ALL)

BoB LoblaW :us: (BOB member since 2007-10-23)

Well, that could be usefull…

Once again, many thanks for sharing your knowledge.


franzy (BOB member since 2007-02-13)