Cause for NullPointerException in jira service plugin?

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

This widget could not be displayed.

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

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

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

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

How to get the getDateQueued() ,

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

ThanQ.. It is Working now..

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.

This widget could not be displayed.

can you share the your code?

This widget could not be displayed.

class JiraCustomMailService extends AbstractService{

MailQueue mailqueue;

public void run() {

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

}

}

This widget could not be displayed.

how your getting "mailqueue" object?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

165 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you