Quantcast

Email notification

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Email notification

Matthias Waller-2
Hi,

I'm using Hudson ver. 1.60 and tried to configure a project to send
e-mails only to the user who broke the build. So I selected the check
boxes "E-mail Notification" and "Send separate e-mails to individuals
who broke the build". The "Recipients" field stayed blank.
With this configuration the following exception occurs:

ERROR: null
java.lang.NullPointerException
        at hudson.tasks.Mailer.perform(Mailer.java:78)
        at hudson.model.Build$1.post(Build.java:348)
        at hudson.model.Run.run(Run.java:513)
        at hudson.model.Build.run(Build.java:290)
        at hudson.model.Executor.run(Executor.java:54)

When I fill one e-mail address in the "Recipients" field it works, but
that's not what I want.

Is there a solution for my request?

Thx
-Matthias

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Email notification

Vladimir Sizikov
Hi Matthias,

Indeed, I can reproduce the exception if no recipients are specified
in the configuration.

The problem, it seems, is due to fact that
MimeMessage.getAllRecipients() returns null when no recipients are
specified, but the code in Huston tries to iterate over all the
recipients, and hence the NPE.

The fix is rather simple (Attached as well):

Index: src/main/java/hudson/tasks/Mailer.java
===================================================================
RCS file: /cvs/hudson/hudson/main/core/src/main/java/hudson/tasks/Mailer.java,v
retrieving revision 1.4
diff -u -r1.4 Mailer.java
--- src/main/java/hudson/tasks/Mailer.java 15 Nov 2006 01:05:02 -0000 1.4
+++ src/main/java/hudson/tasks/Mailer.java 15 Nov 2006 11:41:58 -0000
@@ -75,11 +75,17 @@
         try {
             MimeMessage mail = getMail(build);
             if(mail!=null) {
-                StringBuffer buf = new StringBuffer("Sending e-mails to ");
-                for (Address a : mail.getAllRecipients())
-                    buf.append(' ').append(a);
-                listener.getLogger().println(buf);
-                Transport.send(mail);
+                Address[] allRecipients = mail.getAllRecipients();
+                if(allRecipients!=null) {
+                    StringBuffer buf = new StringBuffer("Sending e-mails to ");
+                    for (Address a : allRecipients)
+                        buf.append(' ').append(a);
+                    listener.getLogger().println(buf);
+                    Transport.send(mail);
+                } else {
+                    listener.getLogger().println("An attempt to send an e-mail"
+                            + " to empty list of recipients, ignored.");
+                }
             }
         } catch (MessagingException e) {
             e.printStackTrace( listener.error(e.getMessage()) );


Kohsuke, could you please review the fix, is it OK?

Thanks,
  --Vladimir

--
Vladimir Sizikov
Sun Microsystems                   [hidden email]


On Wed, Nov 15, 2006 at 10:55:13AM +0100, Matthias Waller wrote:

> Hi,
>
> I'm using Hudson ver. 1.60 and tried to configure a project to send
> e-mails only to the user who broke the build. So I selected the check
> boxes "E-mail Notification" and "Send separate e-mails to individuals
> who broke the build". The "Recipients" field stayed blank.
> With this configuration the following exception occurs:
>
> ERROR: null
> java.lang.NullPointerException
> at hudson.tasks.Mailer.perform(Mailer.java:78)
> at hudson.model.Build$1.post(Build.java:348)
> at hudson.model.Run.run(Run.java:513)
> at hudson.model.Build.run(Build.java:290)
> at hudson.model.Executor.run(Executor.java:54)
>
> When I fill one e-mail address in the "Recipients" field it works, but
> that's not what I want.
>
> Is there a solution for my request?
>
> Thx
> -Matthias
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

NPE_in_Mailer.diff (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Email notification

Kohsuke Kawaguchi
Administrator
Looks good to me. Please go ahead and commit it.

2006/11/15, Vladimir Sizikov <[hidden email]>:

> Hi Matthias,
>
> Indeed, I can reproduce the exception if no recipients are specified
> in the configuration.
>
> The problem, it seems, is due to fact that
> MimeMessage.getAllRecipients() returns null when no recipients are
> specified, but the code in Huston tries to iterate over all the
> recipients, and hence the NPE.
>
> The fix is rather simple (Attached as well):

--
Kohsuke Kawaguchi

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...