From 7af51ede4ea6938347e895a3237710e0c243900a Mon Sep 17 00:00:00 2001 From: Josh Eckels Date: Fri, 23 Aug 2024 13:39:40 -0700 Subject: [PATCH] Avoid NPE sending email on dev machines (#448) --- .../org/labkey/testresults/SendTestResultsEmail.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/testresults/src/org/labkey/testresults/SendTestResultsEmail.java b/testresults/src/org/labkey/testresults/SendTestResultsEmail.java index d09583cd..806dcdd7 100644 --- a/testresults/src/org/labkey/testresults/SendTestResultsEmail.java +++ b/testresults/src/org/labkey/testresults/SendTestResultsEmail.java @@ -2,6 +2,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.jetbrains.annotations.Nullable; import org.labkey.api.data.Container; import org.labkey.api.data.ContainerManager; import org.labkey.api.data.TableSelector; @@ -14,6 +15,7 @@ import org.labkey.api.util.MimeMap; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.Pair; +import org.labkey.api.util.UnexpectedException; import org.labkey.api.view.ActionURL; import org.labkey.testresults.model.BackgroundColor; import org.labkey.testresults.model.RunDetail; @@ -335,15 +337,19 @@ public void execute(String ctx, org.labkey.api.security.User from, String emailT @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { - ValidEmail admin = null; + ValidEmail admin; try { admin = new ValidEmail(DEFAULT_EMAIL.ADMIN_EMAIL); + org.labkey.api.security.@Nullable User adminUser = UserManager.getUser(admin); + if (adminUser != null) + { + execute(MORNING_EMAIL, adminUser, DEFAULT_EMAIL.RECIPIENT); + } } catch (ValidEmail.InvalidEmailException e) { - e.printStackTrace(); + throw UnexpectedException.wrap(e); } - execute(MORNING_EMAIL, UserManager.getUser(admin), DEFAULT_EMAIL.RECIPIENT); } }