It's all about the answers!

Ask a question

[closed] How to get IChangeSet from IItemHandle

Thomas Foyle (12) | asked May 28 '10, 10:18 a.m.
closed Oct 20 '21, 5:48 a.m. by Ralph Schoon (63.1k33646)
Hi all,

I'm trying to use the Plain Java Client to get change set information from a work item. I've got to the point where I have a List of IItemHandles for all the change sets linked with the work item. Now I need to use these handles to get a List of IChangeSets.

public static void getChangeSets(ITeamRepository repository, IWorkItem workItem, IProgressMonitor monitor) {

//Get an IReference to the work item.
ILinkManager linkManager = (ILinkManager) repository.getClientLibrary(ILinkManager.class);
IReferenceFactory referenceFactory = linkManager.referenceFactory();
IReference workItemReference = referenceFactory.createReferenceToItem(workItem.getItemHandle());

//Find all ILinks which attach a change set to the work item.
ILinkQueryPage linkQueryPage = linkManager.findLinksByTarget("", workItemReference, monitor);
ILinkCollection linkCollection = linkQueryPage.getAllLinksFromHereOn();

//Put the ILinks in a list.
List<ILink> changeSetLinks = (List<ILink>)linkCollection.getLinksById("");

//Convert each ILink to an IReference to the change set.
List<IReference> changeSetReferences = new ArrayList<IReference>();
for (ILink link : changeSetLinks) {

//Convert each IReference to an IItemHandle.
List<IItemHandle> itemHandles = new ArrayList<IItemHandle>();
for (IReference reference : changeSetReferences) {

//Convert each IItemHandle to an IChangeSet.
List<IChangeSet> changeSets = new ArrayList<IChangeSet>();
for (IItemHandle itemHandle : itemHandles) {
changeSets.add((IChangeSet)repository.itemManager().fetchCompleteItem(itemHandle, 0, monitor)); //ERROR HERE.


When I run this I get the following PermissionDeniedException error.

Exception in thread "main" java.lang.RuntimeException: CRJAZ1319E Illegal read access: User "" attempted to read item(s) having the following type(s): ChangeSet
at snippets.RtcAccess.getChangeSets(
at snippets.RtcAccess.main(
Caused by: CRJAZ1319E Illegal read access: User "" attempted to read item(s) having the following type(s): ChangeSet
at snippets.RtcAccess.getChangeSets(

Is there some way I can get the required permission to access change sets? Or is there something else I'm doing wrong? Thanks for any help or suggestions.


The question has been closed for the following reason: "Problem is not reproducible or outdated" by rschoon Oct 20 '21, 5:48 a.m.

2 answers

permanent link
Ralph Schoon (63.1k33646) | answered Oct 20 '21, 5:48 a.m.
edited Oct 20 '21, 5:49 a.m.
I close this due to the age of the post.

With respect to the question, one would usually have a change set and try to access the contained changes and the related items. That is a supported and useful direction.

Trying to find the change set that an item is related to from an IItem/IItemHandle as described above does not make a lot of sense. The Item could be affected by several change stets linked to the work item.

You also can not just cast stuff from one class to another, obviously. There must be a subclass or interface relationship to be able to do that.

permanent link
Peter Moraza (481924) | answered Oct 19 '21, 10:30 p.m.

Hi Tom,

I am trying to achieve the same objective you are, retrieving an IChangeSet object from an IItemHandle, but I get a ClassCastException calling the same method you did. I know it has been a long time since you posted your question, but did you overcome your issue? Pasting my method call for comparison with yours. "iref" is an IReference to an IItemHandle.

IChangeSet changeSet = (IChangeSet) repo.itemManager().fetchCompleteItem((ChangeSetHandleImpl) iref.resolve(), IItemManager.DEFAULT, monitor);

My exception:

java.lang.ClassCastException: incompatible with

I'll post my code in a new query. TIA


Ralph Schoon commented Oct 20 '21, 1:59 a.m.

 Please do not ask questions, as answers to other authors questions. Especially if they are 11 years old. Please ask your own question. In your particular case, please check the method signatures, e.g. if they return compatible object types.