Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid NPE when outsite of a job context #413

Merged
merged 2 commits into from
Feb 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/main/java/hudson/plugins/jira/JiraMailAddressResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import hudson.model.Job;
import hudson.model.User;
import hudson.tasks.MailAddressResolver;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.Stapler;

import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Pattern;

Expand All @@ -32,9 +34,17 @@ public String findMailAddressFor(User u) {
}
String username = u.getId();

Job<?, ?> job = Stapler.getCurrentRequest().findAncestorObject( Job.class);
Job<?, ?> job = null;
try {
job = Stapler.getCurrentRequest().findAncestorObject(Job.class);
} catch (NullPointerException e) {
// sadly but outside of a context job this throw an exception
olamy marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.fine("NPE trying to find the Job of the current request");
}

List<JiraSite> sites = job == null ? JiraGlobalConfiguration.get().getSites() : JiraSite.getJiraSites(job);

for (JiraSite site : JiraSite.getJiraSites(job)) {
for (JiraSite site : sites) {
JiraSession session = site.getSession(job);
if (session == null) {
continue;
Expand Down