cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Java.lang.NullPointerException when getting the default representation

BernardWielfaer
6-Contributor

Java.lang.NullPointerException when getting the default representation

I get an error (java.lang.NullPointerException) when executing the following lines at :


This is the code :


PromotionNotice notice = (wt.maturity.PromotionNotice)pr;
StandardMaturityService service = StandardMaturityService.newStandardMaturityService();
QueryResult results = service.getPromotionTargets(notice);
if (results != null)
{
while (results.hasMoreElements())
{
MyObject = (Versioned)results.nextElement();
if (MyObject instanceof EPMDocument)
{
CurrEPM = (EPMDocument) MyObject;
if (CurrEPM.getDocType().getStringValue().equals("wt.epm.EPMDocumentType.CADDRAWING"))
{
// Get the time = now - x hours (x is comming from xml file)
long modTime = 0;
TracePath = TracePath + "\n" + "- docmodtime: " + docmodtime;
long modifiedTime = Long.parseLong(docmodtime);
modTime = currentTime - modifiedTime * 60L * 60L * 1000L;
Timestamp modstamp = new Timestamp(modTime);

// Check if the drawing last change is older than x hours
PersistInfo PerInfo = CurrEPM.getPersistInfo();

// If last modification timestamp of drawing is before the date limit (e.g. now - 3000 hours) then the drawing has not been copyed yet
if (PerInfo.getModifyStamp().before(modstamp))
{
// The modification time of the drawings is before that time, the plot file must be copied
TracePath = TracePath + "\n" + "+2.2 " + "Number: " + CurrEPM.getNumber() + " Name: " + CurrEPM.getName() + " Status: " + CurrEPM.getLifeCycleState().toString() + " Version: " + CurrEPM.getVersionIdentifier().getValue() + " Iteration: " + CurrEPM.getIterationIdentifier().getValue();
<-------
........



TrcaPath =

4 REPLIES 4

Dear Bernard,

It is due to the content holder needing a refresh, but an easy method is

com.ptc.wvs.server.util.PublishUtils.PublishUtils.getRepresentation

Simon
Wincom Consulting

Simon,


The same error occurs, could this be due to the fact that there is no representation yet ?
Regards,


Bernard

Dear Bernard,

Possible, I don’t know fully the behaviour you should try adding one and see what happens.

QueryResult qr = PublishUtils.getRepresentations(myRepresentable);

This is the API I used in test code recently and it should not return a null (could be empty) but you would need to post filter for the default rep. and this has a slight performance hit and so I would be prudent with it.

You should always anticipate that an API might throw an exception.

Good luck,

Simon

The problem occurs when there is no representation, as soon there is one the function executes and returns result.
One would suppose that when there is no representation that it returns NULL, but apparently this one not.

Announcements


Top Tags