It's all about the answers!

Ask a question

How do I access attribute values when I am receiving assertion errors through Plain Java API


Joshua Shapiro (1111) | asked Jul 20 '15, 4:51 p.m.
 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



permanent link
sam detweiler (12.5k6195201) | answered Jul 20 '15, 5:14 p.m.
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



Comments
Joshua Shapiro commented Jul 20 '15, 6:15 p.m.

 Where are you getting the com.ibm.team.apt.common and com.ibm.team.apt.internal.client apis? They weren't in the Plain Java jar files I found on the jazz website


sam detweiler commented Jul 20 '15, 6:31 p.m.

those are in the SDK.
you could remove them and comment out the code


Joshua Shapiro commented Jul 21 '15, 2:49 p.m.

 Thanks for the help! I tried your code and it initially didn't find the attribute for the work item. Once I set a value for the attribute though it found it with no problem. I assumed if I could see the field in workItem online, I should be able to access it. But I can only access it if it was assigned a value. 


sam detweiler commented Jul 21 '15, 2:53 p.m.

hm.. the code should always print an attributes value even when null.

it does NOT print user names, or data/time values.

what kind of attribute is it?


permanent link
Ralph Schoon (63.3k33646) | answered Jul 21 '15, 1:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

Comments
Joshua Shapiro commented Jul 21 '15, 2:51 p.m.

 Thanks for the help! I think what you said about synchronizing attributes may be the issue. The field itself has been added to the old workItems, but using Sam's code the attribute only shows up if I manually change the value of it. And once the value is changed my code works as well. Is this what you were saying? Should I still be able to see the attribute field on an old workItem even if it hasn't been synchronized?


sam detweiler commented Jul 21 '15, 2:55 p.m.

no.. unless you synch, the attribute is NOT there on old workitems.


permanent link
sam detweiler (12.5k6195201) | answered Jul 21 '15, 11:31 a.m.
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())

Comments
Ralph Schoon commented Jul 21 '15, 12:12 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Sam, you didn't report the assertion error.


sam detweiler commented Jul 21 '15, 12:28 p.m. | edited Jul 21 '15, 12:29 p.m.

I catch the assertion error and use it to determine other attribute features

.....
// this will throw exception if not enumeration
                            IEnumeration<iliteral> enumeration = (IEnumeration<iliteral>) workItemCommon
                                    .resolveEnumeration(ia, monitor);



  catch (Exception e)
                    {
                        System.out.println("\t\t\t\tattribute id="
                           

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.