It's all about the answers!

Ask a question

In the Java Server API, How Can I Trap a Permissions Error from a Work Item Save Operation?


Nate Decker (37814761) | asked Aug 04 '15, 8:30 a.m.
I have a follow-up action that saves the work item. Sometimes this action will generate a permissions error. In those cases, I want the operation behavior to abort gracefully without interfering with the save operation. If the permissions error had been an exception, I could have caught it in a try-catch block. However, since a permissions error is something else, I'm not sure how to trap for that scenario and allow a graceful exit of the operation behavior.

Comments
Ralph Schoon commented Aug 04 '15, 8:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Have you tried to catch Throwable? This is the super super class for exceptions as far as I know. You should be able to find out what is thrown, if anything. Otherwise do you check the status of the work item save?

        IStatus saveStatus = fWorkItemServer.saveWorkItem3(parentworkingcopy, null, null,
                additionalParams);
        if (!saveStatus.isOK()) {
            return false;
        }


Nate Decker commented Aug 04 '15, 8:43 a.m. | edited Aug 04 '15, 9:06 a.m.

I am not currently checking the status of the work item save. I'll give that a try. Thanks.

Edit: Unfortunately, neither of those suggestions has panned out. Got any other ideas?

Edit 2: Actually, I just realized that the permissions error is happening long before my saveWorkItem3 operation (it occurs when tracing links). I need to put the try/catch block earlier in the code. I'll try that and come back here.

Edit 3: Looks like the catch Throwable does the trick. Stack exchange seems to argue that it's bad practice to do that though so I guess I need to do some testing to figure out exactly which exception is being thrown for the permissions error. I'll mark your answer as the accepted solution.

Accepted answer


permanent link
Nate Decker (37814761) | answered Oct 09 '15, 9:08 a.m.

I should follow up on this post and provide some more details since I have the solution now. Ralph's answer set me on the correct path, but I just noticed this post in my search results and saw that the answer count was "0" which implied it was still unanswered.

Rather than catching a generic throwable exception, I ultimately found that I needed to catch "PermissionDeniedException". Catching this exception allowed me to continue the operation behavior without failing the save operation.

Ralph Schoon selected this answer as the correct answer

Comments
Ralph Schoon commented Oct 09 '15, 9:18 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Thanks for the update Nate!

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.