Null pointer exception from js call LABKEY.Message.sendMessage

LabKey Support Forum
Null pointer exception from js call LABKEY.Message.sendMessage Will Holtz  2018-03-29 18:46
Status: Closed
 

Hi,

In Labkey v17.1 (and earlier) I could send emails from a dummy user (announce@example.com) in my Labkey instance using the following code:

  <script type="text/javascript">
         function errorHandler(errorInfo, responseObj)
         {
             LABKEY.Utils.displayAjaxErrorResponse(responseObj, errorInfo);
         }
        function onSuccess(result)
         {
             alert('Message sent successfully.');
         }
        LABKEY.Message.sendMessage({
             msgFrom: 'announce@example.com',
             msgSubject: 'Testing email API...',
             msgRecipients: [
                 LABKEY.Message.createRecipient(LABKEY.Message.recipientType.to, 'realuser@example.com'),
             ],
             msgContent: [
                 LABKEY.Message.createMsgContent(LABKEY.Message.msgType.plain, 'This is a test message')
             ],
             success: onSuccess,
             failure: errorHandler,
         });
         </script>

In v18.1 this results in the user viewing the page with the js code to get the error 'An error occurred trying to load: java.lang.NullPointerException' and the following appears in the logs:

WARN SendMessageAction 2018-03-29 18:03:42,943 http-bio-443-exec-8 : The user: announce@example.com is either disabled or has never logged in and has been omitted.
WARN MailHelper 2018-03-29 18:03:43,050 http-bio-443-exec-8 : Exception sending email; check your SMTP configuration in labkey.xml
from: null
to: realuser@example.com
subject: Testing email API...
java.lang.NullPointerException
at org.labkey.api.util.MailHelper.getAddressStr(MailHelper.java:242)
at org.labkey.api.util.MailHelper.addAuditEvent(MailHelper.java:226)
at org.labkey.api.util.MailHelper.send(MailHelper.java:200)
at org.labkey.announcements.SendMessageAction.execute(SendMessageAction.java:132)
at org.labkey.announcements.SendMessageAction.execute(SendMessageAction.java:58)
at org.labkey.api.action.ApiAction.handlePost(ApiAction.java:180)
at org.labkey.api.action.ApiAction.handleRequest(ApiAction.java:125)
at org.labkey.api.action.BaseViewAction.handleRequest(BaseViewAction.java:177)
at org.labkey.api.action.SpringActionController.handleRequest(SpringActionController.java:415)
at org.labkey.api.module.DefaultModule.dispatch(DefaultModule.java:1231)
at org.labkey.api.view.ViewServlet._service(ViewServlet.java:205)
at org.labkey.api.view.ViewServlet.service(ViewServlet.java:132)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.labkey.api.data.TransactionFilter.doFilter(TransactionFilter.java:38)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.labkey.api.module.ModuleLoader.doFilter(ModuleLoader.java:1138)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.labkey.api.security.AuthFilter.doFilter(AuthFilter.java:214)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.labkey.core.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:118)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:279)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

Because my dummy user has never logged into my Labkey instance, getEmail(from) in server/modules/announcements/src/org/labkey/announcements/SendMessageAction.java line 124 returns null in v18.1 and this is the root of the problem. I logged into my dummy account and this resolved the issue for me, but I thought I'd report it in case there is a desire to clean up the error handling here.

-Will

 
 
Jon (LabKey DevOps) responded:  2018-03-30 11:01

Hi Will,

There has been a change in 18.1 regarding the sendMessage API at the end of the Release Notes for 18.1

Changes to Messages API - A new site-scoped role, Use SendMessage API, controls access to the LABKEY.Message API. Only users with this role can send messages via the API. Previously, read permission to a container automatically granted this level of access, so Guests or other groups might need to be added to the new role. Also, in a related change, the server no longer sends emails to users who have never logged into the server, except for the initial invitation email to set up their user account. (docs)

Regards,

Jon

 
Jon (LabKey DevOps) responded:  2018-03-30 14:47
Note: I've been informed that the NPE still shouldn't be happening though. Bug https://www.labkey.org/home/Developer/issues/issues-details.view?issueId=33802 has been filed to investigate the issue.