How do I access attribute values when I am receiving assertion errors through Plain Java API
I'm using the Plain Java API to grab specific details about certain work items. In the past I've been able to access custom attributes by using the workItem.getValue() function. However, some custom attributes were added recently to work items and when I attempt to access their values I'm receiving the following error:
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.getValu
e(WorkItemImpl.java:2849)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocation
Handler.invoke(ItemStore.java:597)
at com.sun.proxy.$Proxy21.getValue(Unknown Source)
at test.ThemeTraversal.fetchAllThemes(ThemeTraversal.java:145)
at test.RunIt.run(RunIt.java:287)
at test.RunIt.main(RunIt.java:139)
I've tested my code on a clone of the production line version and it works fine, but I can't seem to access these attributes for the production line. I'm on version 5.0.2. Anyone having similar issues?
3 answers
see my little sample here https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes
which prints out the attributes of workitems from a query result
which prints out the attributes of workitems from a query result
Comments
If attributes are added to work item type categories, the don't necessarily appear on work items that were created earlier. You have to synchronize the attributes to make that happen. (In the Eclipse UI there is a button Check attributes usage in repository you can use for that or check https://rsjazz.wordpress.com/2012/11/19/using-an-expression-to-synchronize-attributes-for-work-items-of-a-specific-type/ ).
In any case you should check if the work item has the attribute with hasAttribute(IAttribute). See https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
As a side note, you should not use the com.ibm.team.apt.common and com.ibm.team.apt.internal.client api unless you are working with plans (which is unsupported) use the com.ibm.team.workitem.client. and com.ibm.team.workitem.common API's that are also available in the plain Java Client Libraries.
In any case you should check if the work item has the attribute with hasAttribute(IAttribute). See https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
As a side note, you should not use the com.ibm.team.apt.common and com.ibm.team.apt.internal.client api unless you are working with plans (which is unsupported) use the com.ibm.team.workitem.client. and com.ibm.team.workitem.common API's that are also available in the plain Java Client Libraries.
Comments
my sample does check
// loop thru all the workitem attributes
for (IAttribute ia : workItemCommon.findAttributes(projectArea,
monitor))
{
// if this workitem has this attribute and
// its nOT an internal use attribute
if (workItem.hasAttribute(ia) && !ia.isInternal())
// loop thru all the workitem attributes
for (IAttribute ia : workItemCommon.findAttributes(projectArea,
monitor))
{
// if this workitem has this attribute and
// its nOT an internal use attribute
if (workItem.hasAttribute(ia) && !ia.isInternal())