It's all about the answers!

Ask a question

How can I solve NullPointerException for Calculated Value applied to Timestamp in RTC 3.0.1.1?


Andrew Trobec (49713144139) | asked Mar 12 '13, 10:30 a.m.
Hello,

I have a custom attribute of type timestamp and there is a calculated value attribute customization associated with it that will insert a date value based on certain conditions.

I have noticed that the script will throw a java.lang.NullPointerException when it doesn't meet the conditions for setting a date value, presumably because it won't accept "null" as a return value even though the value, if read from the attribute, is currently "null" (in some cases the attribute does not need to be set and so null should be valid).

Is there any way of programming the script so that the java.lang.NullPointerException doesn't appear?

I have tried to remove the return completely but that doesn't change anything.

Any ideas?

Regards,

Andrew

3 answers



permanent link
Eric Jodet (6.3k5111120) | answered Mar 12 '13, 11:07 a.m.
JAZZ DEVELOPER
Hello Andrew,
details on the NPE (stack) and a look at the js source code would help here.
I these can't be shared in the open, feel free to send them to me.

Thanks.
Eric.

Comments
Andrew Trobec commented Mar 12 '13, 11:42 a.m.

 Hello Eric,


I added a response as another answer to this question since there I did not have enough characters to write here.

Regards,

Andrew


permanent link
Andrew Trobec (49713144139) | answered Mar 12 '13, 11:34 a.m.
Hello Eric,

Thank you for your interest.  Since the comment is too small, I will give you the info here in a reply in the thread:

The NPE:

java.lang.NullPointerException
at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.convert(ScriptAttributeValueProvider.java:186)
at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.getValue(ScriptAttributeValueProvider.java:66)
at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeValueProvider.getValue(AttributeValueProviderRegistry.java:43)
at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.getValue(AttributeImpl.java:898)
at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
at $Proxy31.getValue(Unknown Source)
at com.ibm.team.workitem.common.internal.WorkItemCommon.createWorkItem(WorkItemCommon.java:221)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.createNewUnconnected(WorkItemWorkingCopyRegistry.java:586)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.connectNew(WorkItemWorkingCopyRegistry.java:580)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyManager.connectNew(WorkItemWorkingCopyManager.java:94)
at com.ibm.team.workitem.client.WorkItemOperation.run(WorkItemOperation.java:230)
at com.ibm.team.workitem.client.WorkItemOperation.run(WorkItemOperation.java:189)
at com.ibm.team.workitem.rcp.ui.internal.actions.NewWorkItemAction$2.runProtected(NewWorkItemAction.java:338)
at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

And the code is here:

dojo.provide("com.acn.adt.workitem.calculatedvalue.AutoLastStatusChange");

(function() {
dojo.declare("com.acn.adt.workitem.calculatedvalue.AutoLastStatusChange", null, {

    getValue: function(attributeId, workItem, configuration) {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var currentLength = workItem.getValue("com.acn.adt.attribute.changerequest.hasstatechanged").length;
if (workItem.getValue(WorkItemAttributes.STATE) == "com.acn.adt.workitem.workflow.changerequest.state.s1") {
var today = new Date();
return today.getTime() + "";
}
else if(workItem.getValue("com.acn.adt.attribute.changerequest.hasstatechanged").substr(currentLength-1,1) == "t") {
var today = new Date();
return today.getTime() + "";
}
else {
return null;
}
}
});
})();

When a new work item is created the script is run and it goes to the else statement which is "return null;".  This throws the "java.lang.NullPointerException".  I have even tried "return workItem.getValue(attributeId)" which the current value, but I get the same exception.

Best regards,

Andrew

permanent link
Eric Jodet (6.3k5111120) | answered Mar 12 '13, 11:51 a.m.
JAZZ DEVELOPER
Thanks Andrew,
the line:
var currentLength = workItem.getValue("com.acn.adt.attribute.changerequest.hasstatechanged").length;
might be the suspect.
if returned value is null, then you'll get the NPE
no?

Comments
Andrew Trobec commented Mar 12 '13, 12:37 p.m.

I don't think this causes the error.  It is just one example where I have a calculated value for a timestamp that, when returning null, gives me the java.lang.NullPointerException.  If I replace the content of the else clause with

var today = new Date();
return today.getTime() + "";
Then everything works fine.  I want to be able to return null, or at least stop the script throwing the exception.
Regards,
Andrew

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.