It's all about the answers!

Ask a question

NPE creating a new attachment


Dave Draeger (4172) | asked Jul 23 '08, 6:57 p.m.
I'm trying to create a new attachment using the following code and I keep
getting a null pointer exception. My guess is that I'm not allowed to have
a null project area when creating a new attachment but I'm not able to find
any documentation or javadoc that mentions that. Also, when I look up
existing attachments and invoke the getProjectArea() method, all of them
return null so that makes me think that by not providing a project area, the
attachment is simply not associated with a specific project and can be
linked to by any workitem.

Can someone shed some light on this? Thanks!


Here is the code:
===============================================================
I first would iterate through existing work items finding the ones that had
references to attachments. I would then get that attachment handle:

IAuditableHandle handle = (IAuditableHandle) ((IItemReference)
ref).getReferencedItem();

if (handle instanceof IAttachmentHandle) {

// IAttachment attachment = auditableClient.fetchCurrentAuditable(handle,
IAttachment.FULL_PROFILE, monitor);

IAttachment attachment = auditableClient.resolveAuditable(handle,
IAttachment.FULL_PROFILE, monitor);

-------------------------------------------------------------------------------------------------
The "attachment" variable above is the "a" variable below. So I have a
fully resolved Attachment object and then I'm just trying to create an exact
copy of the existing attachment using the code below:
NOTE: pa = IProjectArea of the existing attachment and it is always null.


// Get the contents of the original attachment
ByteArrayOutputStream bos = new ByteArrayOutputStream();

serviceContent.retrieveContent(a.getContent(), bos, null);

byte[] content = bos.toByteArray();


// Create the new attachment in the repository

IAttachment attachmentNew = serviceNewWI.createAttachment(pa, a.getName(),
a.getDescription(), a.getContent().getContentType(),
a.getContent().getCharacterEncoding(), new ByteArrayInputStream(content),
monitor);

--------------------------------------------
The result is the following stacktrace:

Exception in thread "main"
com.ibm.team.repository.common.transport.ServiceMethodInvocationError:
java.lang.NullPointerException
at
com.ibm.team.repository.transport.client.RemoteTeamService.getAppropriateException(RemoteTeamService.java:571)
at
com.ibm.team.repository.transport.client.RemoteTeamService.executeMethod(RemoteTeamService.java:474)
at
com.ibm.team.repository.transport.client.RemoteTeamService.invoke(RemoteTeamService.java:184)
at
com.ibm.team.repository.transport.client.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:43)
at $Proxy16.save(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at
com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invokeServiceCall(ServiceInterfaceProxy.java:149)
at
com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invoke(ServiceInterfaceProxy.java:84)
at $Proxy16.save(Unknown Source)
at
com.ibm.team.workitem.client.internal.WorkItemSaveTransport$1.run(WorkItemSaveTransport.java:33)
at
com.ibm.team.repository.client.internal.TeamRepository$3.run(TeamRepository.java:1123)
at
com.ibm.team.repository.common.transport.CancelableCaller.call(CancelableCaller.java:76)
at
com.ibm.team.repository.client.internal.TeamRepository.callCancelableService(TeamRepository.java:1116)
at
com.ibm.team.workitem.client.internal.WorkItemSaveTransport.call(WorkItemSaveTransport.java:30)
at
com.ibm.team.workitem.client.internal.WorkItemSaveRunnable.run(WorkItemSaveRunnable.java:37)
at
com.ibm.team.process.common.advice.ProcessRunnable.internalRun(ProcessRunnable.java:123)
at
com.ibm.team.process.internal.common.advice.runtime.OperationAdviceManager.runRunnable(OperationAdviceManager.java:1317)
at
com.ibm.team.process.internal.common.advice.runtime.OperationAdviceManager.execute(OperationAdviceManager.java:192)
at
com.ibm.team.process.internal.client.ProcessClientService.execute(ProcessClientService.java:566)
at
com.ibm.team.workitem.client.internal.WorkItemClient.save(WorkItemClient.java:538)
at
com.ibm.team.workitem.client.internal.WorkItemClient.save(WorkItemClient.java:526)
at
com.ibm.team.workitem.common.internal.WorkItemCommon.internalSaveAuditables(WorkItemCommon.java:999)
at
com.ibm.team.workitem.common.internal.WorkItemCommon.internalSaveAuditables(WorkItemCommon.java:984)
at
com.ibm.team.workitem.common.internal.WorkItemCommon.saveAuditables(WorkItemCommon.java:976)
at
com.ibm.team.workitem.common.internal.WorkItemCommon.saveAuditable(WorkItemCommon.java:966)
at
com.ibm.team.workitem.common.internal.WorkItemCommon.saveAttachment(WorkItemCommon.java:832)
at
com.ibm.team.workitem.client.internal.WorkItemClient.createAttachment(WorkItemClient.java:521)
at snippets.Migrate1.migrateAttachments(Migrate1.java:257)
at snippets.Migrate1.main(Migrate1.java:158)
Caused by: java.lang.NullPointerException


Any thoughts??

--
Dave Draeger
IBM WebSphere Serviceability Development

2 answers



permanent link
Dave Draeger (4172) | answered Jul 28 '08, 1:04 p.m.
Ah, yes, that makes sense now as the work items were created using M3 (Beta 1) and then we used the repotools from Beta
2 / Beta 3 / GA to migrate the tasks up to GA. Then I was taking a look at the tasks in the GA server after they were
migrated and thus they had no project area associated with them.

--
Dave Draeger
IBM WebSphere Serviceability Development
"Christof Marti" <christof_marti> wrote in message news:g6ju1a$dvu$1@localhost.localdomain...
There should indeed be a project area, only attachments created prior to Beta2 could still have none. How did you
create the attachments having no project area?

Christof
Jazz Work Item team

permanent link
Christof Marti (681) | answered Jul 28 '08, 3:55 a.m.
There should indeed be a project area, only attachments created prior to Beta2 could still have none. How did you create the attachments having no project area?

Christof
Jazz Work Item team

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.