fix:handle edge case for empty recipients to prevent crash#1537
fix:handle edge case for empty recipients to prevent crash#1537Rashmi1613 wants to merge 10 commits intojenkinsci:mainfrom
Conversation
|
I went through the diff and noticed a few things
context.getListener().getLogger().println(...)
Overall the fix definitely makes sense. |
|
@ArpanC6 Thanks for the feedback! I have moved the recipient check after executePresendScript(). I have kept the current logging approach for consistency ,but happy to update if preferred. |
| import java.net.MalformedURLException; | ||
| import java.net.SocketException; | ||
| import java.net.URL; | ||
| import java.util.*; |
| import java.util.Date; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Arrays; |
There was a problem hiding this comment.
I don't mean to harp on this, or seem like I am nitpicking, but please follow the existing format for imports, which is alphabetical order. You can see that most (if not all) java.util imports are listed in alphabetical order.
| return false; | ||
| } | ||
|
|
||
| if (StringUtils.isNotBlank(getDescriptor().getEmergencyReroute())) { |
There was a problem hiding this comment.
I think the ordering here is incorrect. Even if the set of TO/CC/BCC is empty, if the emergency reroute is setup, then that should be sent still.
Previously, if
msg.getAllRecipients()returned null or an empty array,the code attempted to access
allRecipients[0], which could lead toNullPointerException or ArrayIndexOutOfBoundsException.
This change adds a safety check to prevent crashes and logs a clear message instead.
Changes Made
allRecipientsallRecipients[0]Testing