简体   繁体   中英

Play framework 1.2.4: NullPointerException in the constructor of play.exceptions.MailException

The problem is the following:

When sending a mail in webapp running on Play framework 1.2.4 exception with following stack trace can be observed in logs:

Execution exception 
NullPointerException occured : null 

play.exceptions.JavaExecutionException 
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231) 
        at Invocation.HTTP Request(Play!) 
Caused by: java.lang.NullPointerException 
        at play.exceptions.MailException.<init>(MailException.java:27) 
        at play.libs.Mail.buildMessage(Mail.java:79) 
        at play.libs.Mail.send(Mail.java:35) 
        at play.mvc.Mailer.send(Mailer.java:347) 
        at play.mvc.Mailer.sendAndWait(Mailer.java:355) 
        at notifiers.Mails.forgotPassword(Mails.java:19) 
        at controllers.PasswordReset.requestPasswordReset(PasswordReset.java:102) 
        at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548) 
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502) 
        at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478) 
        at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473) 
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161) 
        ... 1 more 

The relevant part here is following:

Caused by: java.lang.NullPointerException 
        at play.exceptions.MailException.<init>(MailException.java:27) 

which indicates that NullPointerException was thrown from constructor of play.exceptions.MailException (in 27th line). Source code of this constructor looks like the following:

public MailException(String message, Throwable cause) {
    super(message, cause);
    StackTraceElement element = getInterestingStrackTraceElement(cause);
    if(element != null) {
        ApplicationClass applicationClass = Play.classes.getApplicationClass(element.getClassName());
        sourceFile = applicationClass.javaFile.relativePath(); // this line is 27th and NPE is thrown from here
        source = Arrays.asList(applicationClass.javaSource.split("\n"));
        line = element.getLineNumber();
    }
}

So either applicationClass local variable or javaFile property is null. Could someone familiar with Play framework weird internals advise what can cause this problem?

Thanks a lot in advance

EDIT after Seb Cesbron answer

We also inspected play.libs.Mail.buildMessage(Mail.java:79) where it is clearly seen that from address is null, but after fixing that, similar exception popped up:

play.exceptions.JavaExecutionException
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
    at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
    at play.exceptions.MailException.<init>(MailException.java:27)
    at play.mvc.Mailer.send(Mailer.java:349)
    at play.mvc.Mailer.sendAndWait(Mailer.java:355)
    at notifiers.Mails.forgotPassword(Mails.java:19)
    at controllers.PasswordReset.requestPasswordReset(PasswordReset.java:102)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)

And there, play.mvc.Mailer.send method contains nearly 200 lines of code enclosed in try-catch block, so it got really tricky to find out what was the problem :)

Line 79 in Mail.java refers to a throw MailException because there is no from address.

The NullPointerException in MailException seems to show that there is no file associated to your mail. Are you sure that the file Mails/forgotPassword.html (or txt) exists ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM