How to fix NullPointerException due to deprecated getPeer() method?
![](http://jazz.net/_images/myphoto/c92d1d223a2b082858f3908dad40e651.jpg)
Hi,
ITeamBuildClient teamBuildClient = (ITeamBuildClient) teamRepository.getClientLibrary(ITeamBuildClient.class);
o
IWorkspaceManager workspaceManager = (IWorkspaceManager) teamRepository.getClientLibrary(IWorkspaceManager.class);
or
IAuditableClient auditableClient = (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
These work fine and I am able to query relevant information with all of them, with the exception of IWorkItemClient or IWorkItemCommon. If I do:
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
java.lang.NullPointerExceptionat com.ibm.team.workitem.common.internal.DeliverableCache.<init>(DeliverableCache.java:35)at com.ibm.team.workitem.common.internal.WorkItemCommon.<init>(WorkItemCommon.java:168)at com.ibm.team.workitem.client.internal.WorkItemClient.<init>(WorkItemClient.java:368)at com.ibm.team.workitem.client.internal.WorkItemClientLibraryFactory.createClientLibrary(WorkItemClientLibraryFactory.java:17)at com.ibm.team.repository.client.internal.ClientLibraryFactoryRegistry.getClientLibrary(ClientLibraryFactoryRegistry.java:90)at com.ibm.team.repository.client.internal.TeamRepository.getClientLibrary(TeamRepository.java:519)at test.ScmTest.main(ScmTest.java:162)
I have also tried to get around the problem by using IQueryableAttributeFactory, but that also gives a NPE in the following form:
java.lang.NullPointerExceptionat com.ibm.team.workitem.common.internal.expression.WorkItemQueryAttributeFactory.cacheCustomAttributesFromWorkitemTypes(WorkItemQueryAttributeFactory.java:444)at com.ibm.team.workitem.common.internal.expression.WorkItemQueryAttributeFactory.updateCache(WorkItemQueryAttributeFactory.java:132)at com.ibm.team.workitem.common.internal.util.CacheHelper.internalCheckCache(CacheHelper.java:114)at com.ibm.team.workitem.common.internal.util.CacheHelper.checkCache(CacheHelper.java:89)at com.ibm.team.workitem.common.internal.expression.WorkItemQueryAttributeFactory.findAttribute(WorkItemQueryAttributeFactory.java:97)at test.ScmTest.main(ScmTest.java:131)
I have also tried a couple of other techniques but all lead to the same end issue, which is that a part of the code calls the (deprecated) IAuditableCommon.getPeer() method, which always returns a null. What is the purpose of that method and is there a way to get around it, especially in the context of getting an instance of IWorkItemClient?
Thanks.
Accepted answer
![](http://jazz.net/_images/myphoto/c92d1d223a2b082858f3908dad40e651.jpg)
hm.. I would use the classpath to the folder -classpath path/*
I would try your app without the maven goo first..
on my sample, I just changed it to use V5 to verify for my answer, so it WILL work if you get the right jars there..
2 other answers
![](http://jazz.net/_images/myphoto/c92d1d223a2b082858f3908dad40e651.jpg)
see my sample code here,
https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes
the accepted answer, which will print the attributes of workitems returned from a (pre-defined) query.
shows all the services connected, etc.. plain java
watch out for the forum changing code inside <> to all lower case.
https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes
the accepted answer, which will print the attributes of workitems returned from a (pre-defined) query.
shows all the services connected, etc.. plain java
watch out for the forum changing code inside <> to all lower case.
Comments
![](http://jazz.net/_images/myphoto/c92d1d223a2b082858f3908dad40e651.jpg)
Hi,
Thanks for the answer, but it does not fix my current predicament with the getPeer() method always returning nulls.
In your example, the queryClient.findSharedQueries() line eventually calls AuditableCommon.update(AuditableCommon.java:183), which causes a NPE because of the previous line's use of getPeer(IWorkItemCommon.class);
![](http://jazz.net/_images/myphoto/c92d1d223a2b082858f3908dad40e651.jpg)
how did you define the set of plain java jar files used by your application?
on mine in Eclipse I made a user Library that points to the entire plain java folder.
(both windows & linux the same approach).
this utility has worked unchanged since 3.0 without unexpected exceptions
same on 5.0 just now
there are 8 plans available and 8 records
Query result initialized: true accurate: true estimated: -1 available: 7 total: 7
1 1 Define a new build
processing for variable=Archived attrib type=boolean kind=
attribute id=archived, type=boolean value=false
processing for variable=Filed Against attrib type=category kind=
Category name=test cacdf 5
processing for variable=Restricted Access attrib type=uuid kind=null
attribute id=contextId, type=uuid value=[UUID _bkmAEO5NEeO7H9hzQ2Ddug]
processing for variable=Corrected Estimate attrib type=duration kind=null
attribute id=correctedEstimate, type=duration value=-1
processing for variable=Creation Date attrib type=timestamp kind=null
attribute id=creationDate, type=timestamp value=2014-06-07 09:10:29.868
altho u say 'plain java', it sounds like you are trying to do this server side, cause you shouldn't need to use getpeer() on the client. (see my code that loads IWorkItemCommon.class).
you can do the same thing on the server side.
add IWorkItemCommon.class as a plugin requiredService
then use the AbstractService.getService(IWorkItemCommon.class).
(your plugin should extend AbstractService)
for example
IWorkItemServer workItemService = getService(IWorkItemServer.class);
on mine in Eclipse I made a user Library that points to the entire plain java folder.
(both windows & linux the same approach).
this utility has worked unchanged since 3.0 without unexpected exceptions
same on 5.0 just now
there are 8 plans available and 8 records
Query result initialized: true accurate: true estimated: -1 available: 7 total: 7
1 1 Define a new build
processing for variable=Archived attrib type=boolean kind=
attribute id=archived, type=boolean value=false
processing for variable=Filed Against attrib type=category kind=
Category name=test cacdf 5
processing for variable=Restricted Access attrib type=uuid kind=null
attribute id=contextId, type=uuid value=[UUID _bkmAEO5NEeO7H9hzQ2Ddug]
processing for variable=Corrected Estimate attrib type=duration kind=null
attribute id=correctedEstimate, type=duration value=-1
processing for variable=Creation Date attrib type=timestamp kind=null
attribute id=creationDate, type=timestamp value=2014-06-07 09:10:29.868
altho u say 'plain java', it sounds like you are trying to do this server side, cause you shouldn't need to use getpeer() on the client. (see my code that loads IWorkItemCommon.class).
you can do the same thing on the server side.
add IWorkItemCommon.class as a plugin requiredService
then use the AbstractService.getService(IWorkItemCommon.class).
(your plugin should extend AbstractService)
for example
IWorkItemServer workItemService = getService(IWorkItemServer.class);
Comments
![](http://jazz.net/_images/myphoto/c92d1d223a2b082858f3908dad40e651.jpg)
I'm building with Maven, which gets its RTC plugin jars from our Nexus server.
Then for execution, I have a batch file that has a reaaaally long classpath with all the needed jars in it (just the ones I need though). This is meant to be executed as a client, I do not have the server stuff installed on my machine. And I also do not use getPeer() explicitly, it's just that for every attempt I make to get the client (including exactly as you have done it) eventually the getPeer() method gets called from within the RTC code and I have no way of bypassing it.