It's all about the answers!

Ask a question

How to fix NullPointerException due to deprecated getPeer() method?


Nicolas Poisson (1023) | asked Jun 18 '14, 1:51 p.m.
Hi,

I am trying to write code that uses the RTC Plain Java API to perform some queries on work items for reporting purposes. I am using RTC 4.0.3. I am able to get references to most clients using the often demonstrated technique of doing, for example, 

ITeamBuildClient teamBuildClient = (ITeamBuildClient) teamRepository.getClientLibrary(ITeamBuildClient.class);
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);

I get the following stacktrace:

java.lang.NullPointerException
        at 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.NullPointerException
        at 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


permanent link
sam detweiler (12.5k6195201) | answered Jun 18 '14, 4:43 p.m.

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..

Nicolas Poisson selected this answer as the correct answer

Comments
Nicolas Poisson commented Jun 19 '14, 8:38 a.m.

I have set the classpath to the entire folder as you suggested instead of picking and choosing the jars to use and it is now working as expected (with maven).


Thanks for your time.

2 other answers



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

Comments
Nicolas Poisson commented Jun 18 '14, 3:10 p.m.

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);


permanent link
sam detweiler (12.5k6195201) | answered Jun 18 '14, 3:31 p.m.
edited Jun 18 '14, 3:52 p.m.
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);


Comments
Nicolas Poisson commented Jun 18 '14, 4:26 p.m.

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. 


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.