It's all about the answers!

Ask a question

NPE using IProcessAreaWorkingCopy


Sian O'Briain (35821) | asked Mar 07 '17, 7:57 a.m.

Version 6.0.3 (also had same problem with Version 5.0.2)

Hi I am using the plain client java api to automate adding users to a team area. However I am getting an intermittent NPE which seems to be related to instantiating the working copy. I get the NPE most times but sometimes not, seems related to the amount of times I instatiate the IProcessAreaWorkingCopy class. Stack trace below

IWorkingCopyManager copyManager = processItem.getWorkingCopyManager();
IProcessAreaWorkingCopy workingCopy
...
//loop through each team area{
...
     workingCopy = (IProcessAreaWorkingCopy)copyManager.getWorkingCopy(teamArea);
     //add or remove members
    ...
    workingCopy.save(null);
    copyManager.disconnect(teamArea);
    //adding next line doesn't seem to make a difference
    workingCopy.dispose();
}



Error:

java.lang.NullPointerException
    at com.ibm.team.process.internal.client.workingcopies.ProcessAreaWorkingCopy.handleProcessAreaChanged(ProcessAreaWorkingCopy.java:978)
    at com.ibm.team.process.internal.client.workingcopies.ProcessAreaWorkingCopy.access$1(ProcessAreaWorkingCopy.java:968)
    at com.ibm.team.process.internal.client.workingcopies.ProcessAreaWorkingCopy$SharedItemChangeListener.itemsChanged(ProcessAreaWorkingCopy.java:139)
    at com.ibm.team.repository.client.internal.ItemManager.dispatchEvents(ItemManager.java:1395)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher$2.run(EventSource.java:739)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher.process(EventSource.java:732)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher$3.run(EventSource.java:771)
    at com.ibm.team.repository.client.util.ThreadCheck.runProhibitingLongOps(ThreadCheck.java:174)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher.process(EventSource.java:756)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher$4.run(EventSource.java:790)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Mar 07, 2017 12:50:52 PM com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher$2 handleException
SEVERE: Exception occured in process
java.lang.NullPointerException
    at com.ibm.team.process.internal.client.workingcopies.ProcessAreaWorkingCopy.handleProcessAreaChanged(ProcessAreaWorkingCopy.java:978)
    at com.ibm.team.process.internal.client.workingcopies.ProcessAreaWorkingCopy.access$1(ProcessAreaWorkingCopy.java:968)
    at com.ibm.team.process.internal.client.workingcopies.ProcessAreaWorkingCopy$SharedItemChangeListener.itemsChanged(ProcessAreaWorkingCopy.java:139)
    at com.ibm.team.repository.client.internal.ItemManager.dispatchEvents(ItemManager.java:1395)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher$2.run(EventSource.java:739)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher.process(EventSource.java:732)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher$3.run(EventSource.java:771)
    at com.ibm.team.repository.client.util.ThreadCheck.runProhibitingLongOps(ThreadCheck.java:174)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher.process(EventSource.java:756)
    at com.ibm.team.repository.client.util.EventSource$BackgroundEventDispatcher$4.run(EventSource.java:790)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)



Comments
Sian O'Briain commented Mar 07 '17, 8:09 a.m.

Previously I was using the ProcessAreaWorkingCopy class before I found this IProcessAreaWorkingCopy class. Previously I saw this error when deleting members but now it only seems to come up when adding roles. I have tried to use both methods

workingCopy.getTeam().addContributorsSettingRoleCast(userObjectArray,new IRole[]{teamMemberRole});

and also adding contributors and then setting role:
workingCopy.getTeam().setRoleCast(contrib, teamMemberRoleArray);


Sian O'Briain commented Mar 07 '17, 8:32 a.m.

actually no, a red herring, seeing again for deletes:

Accepted answer


permanent link
Ralph Schoon (62.9k33645) | answered Mar 07 '17, 8:32 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

In Snippet3 of the plain Java client Libraries there is no disconnect or dispose:

    IRole role = getRole(area);
    teamArea = (ITeamArea) items[1];

    IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy)service.getWorkingCopyManager().createPrivateWorkingCopy(teamArea);
    areaWc.getTeam().addContributorsSettingRoleCast(
            new IContributor[] {repo.loggedInContributor()}, 
            new IRole[] {role});
    areaWc.save(monitor);

    monitor.subTask("Created project and team called " + area.getName());
    return teamArea;

I use this code and it does not disconnect either
    /*
     * Adds a user as a member with a specific role to a process area
     * 
     * @param user
     * @param role
     * @param processArea
     * @param itemService
     * @param monitor
     * @throws TeamRepositoryException
     /
    public static void addMemberToProcessArea(IContributor user, IRole role,
            IProcessArea processArea, IProcessItemService itemService,
            IProgressMonitor monitor) throws TeamRepositoryException {
        IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy) itemService
                .getWorkingCopyManager().createPrivateWorkingCopy(
                        processArea);
        areaWc.getTeam().addContributorsSettingRoleCast(
                new IContributor[] { user }, new IRole[] { role });
        areaWc.save(monitor);
    }

Sian O'Briain selected this answer as the correct answer

Comments
Sian O'Briain commented Mar 07 '17, 9:34 a.m.

thanks but I also tried using .createPrivateWorkingCopy(teamArea) instead of .getWorkingCopy(teamArea)

I only see the null pointer exception when I have to update multiple teams so in my loop I set areaWc each time.....


Sian O'Briain commented Mar 07 '17, 9:36 a.m. | edited Mar 07 '17, 9:43 a.m.

sorry I misunderstood! I had tried using .createPrivateWorkingCopy(teamArea) but had left in the copyManager.connect(teamArea)

This seems to be working fine now, thanks for your help!


Ralph Schoon commented Mar 07 '17, 10:05 a.m. | edited Mar 07 '17, 10:06 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I have not used it for multiple project areas/team areas, sorry. There might be more effective API that can do more in parallel, but I have not looked that deep. This was sufficient for my needs.


Great that it is working for you now.

Your answer


Register or to post your answer.