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 (111) | 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(
        at org.eclipse.core.runtime.Assert.isTrue(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
        at java.lang.reflect.Method.invoke(
        at com.sun.proxy.$Proxy21.getValue(Unknown Source)
        at test.ThemeTraversal.fetchAllThemes(
        at test.RunIt.main(

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

which prints out the attributes of workitems from a query result

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

 Where are you getting the and 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 (62.9k33645) | answered Jul 21 '15, 1:40 a.m.
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 ).

In any case you should check if the work item has the attribute with hasAttribute(IAttribute). See

As a side note, you should not use the and api unless you are working with plans (which is unsupported) use the and API's that are also available in the plain Java Client Libraries.

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,

                // if this workitem has this attribute and
                // its nOT an internal use attribute
                if (workItem.hasAttribute(ia) && !ia.isInternal())

Ralph Schoon commented Jul 21 '15, 12:12 p.m.

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.