Cause for NullPointerException in jira service plugin?

Nageswarara Rao March 31, 2013

Hi,

I wrore a new jira custom plugin , in this i m trying to read the mailqueue size using size() method from MailQueue Interface , here i got the NullpointerException , i can't understand why it happens?

4 answers

1 vote
Graeme Mitchell March 31, 2013

You're not initialising mailqueue so it's just null based on the snipped you've sent, hense why you get the nullpointerexception. You need to initialise it, something like this:-

MailQueue mailqueue = ComponentAccessor.getMailQueue();

Or alternatively, just do this:-

int mbsize = ComponentAccessor.getMailQueue().size();

Nageswarara Rao April 1, 2013

Hi Mitchell,

instatiated the mailQueue is fine same as for MailQueItem how can i instatiate , when i m using ComponentAccessor for this there is no method like getMailQueueItem()

Graeme Mitchell April 1, 2013

It depends what you're trying to do exactly. This would get an item being sent:-

MailQueue mailqueue = ComponentAccessor.getMailQueue();
MailQueueItem mailqueueitem = mailqueue.getItemBeingSent();

This would get a list of items in the queue in the form of a java queue:-

MailQueue mailqueue = ComponentAccessor.getMailQueue();
Queue<MailQueueItem> mailqueueitem = mailqueue.getQueue();

This would get the error queue in the form of a java queue:-

MailQueue mailqueue = ComponentAccessor.getMailQueue();
Queue<MailQueueItem> mailqueueitem = mailqueue.getErrorQueue();

Nageswarara Rao April 1, 2013

i want to get getDateQueued() , i m searching for that..

How to get the getDateQueued() ,

Graeme Mitchell April 1, 2013

You're deviating from the original question a little here, I don't want to write up your entire requirement. You need to understand that the examples I gave you above are giving you a collection of mail items (in the exception of the first which fetches the one being sent). A mail queue may have multiple mail items and in two of the three examples I gave, we're populating a collection of MailItem. If you fetch a collection, you have to iterate round the mailitems in that collection. The below example will load each item in the queue and iterate round each one getting you the queue date of each item. This is a basic framework that you can work from to make it fit your requirement. If you have any further questions, please ask it on a new question and mark this as resolved:-

MailQueue mailqueue = ComponentAccessor.getMailQueue();
Queue<MailQueueItem> mailqueueitems = mailqueue.getQueue();
        
Iterator<MailQueueItem> ite = mailqueueitems.iterator();
        
while (ite.hasNext())
{
    MailQueueItem mailqueueitem = ite.next();
    Date itemqueuedate = mailqueueitem.getDateQueued();
}

Nageswarara Rao April 1, 2013

ThanQ.. It is Working now..

tousifs
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 1, 2013

Hi Nageswarara Rao,

I found your taking lots of help from answers.atlassian community but not accepting any answers.

i geuss do you know the importance and value of accepting answers from community i request you please accept the answere if it work for you it could be helpful to others.

regards,

tousif shaikh.

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 31, 2013

how your getting "mailqueue" object?

0 votes
Nageswarara Rao March 31, 2013

class JiraCustomMailService extends AbstractService{

MailQueue mailqueue;

public void run() {

sizequeue = mailqueue.size();// here i got the plroblem

}

}

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 31, 2013

can you share the your code?

Suggest an answer

Log in or Sign up to answer