You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Allen <al...@earthlink.net> on 2000/11/05 16:51:56 UTC

Super strange Null Pointer error...

Hi,

Config:
Tomcat 3.1 (Final)
Win 98
MySQL 3.23
JavaMail 1.1.3
Apache 1.3.9
JDK 1.2.2-005

I am having a very strange null pointer error that I just can't seem to
figure out at all.

I have a web application (created the WAR file per specs) in the webapps
directory of Tomcat that Tomat expands the first time that it starts up
and runs fine as long as Tomcat is up. I have a line of code that calls
a static function that creates a mail message (see code below) that I
call through a servlet (haven't bothered adding threading yet, since I
just want to get this part working).

Now, here is the strange part. If I stop Tomcat and restart it, I get a
null pointer if I run this very same code (at the time that I create the
MimeMessage object). I can even shutdown (like power off) my computer
and restart it and still get this null pointer. I can delete ALL of the
files in my webapp directory (including the directory it creates for it
directly under WEB-INF, unjar the WAR file myself and STILL get this
error.

But, if I delete the expanded web application, and let Tomcat unjar the
WAR file it works perfectly (without fail!). I can call the function as
many times as I like (I tried everything from 1 to 30+ times and it
always works in this configuration). But, the minute that I stop and
start Tomcat it starts to fail in the exact same place. I have made sure
that no file dates or sizes change (nor are missing) when Tomat starts
up as opposed to my unjarring it by hand. I have tried copying the web
app over from where I compile it... Same problem.

The ONLY way this code executes without a null pointer is if I let
Tomcat expand the WAR file and keep Tomcat up.

Since I don't believe in magic, there has GOT to be a simple answer to
this that I am just missing... Any ideas?

Below is a code snippet and the stack trace. I posted this to the
JavaMail interest group to try to see if this is just a JavaMail
problem, but because of what I described above, I suspect it may not be.
The only good news here is that this is just my dev box, I am using
Solaris on my prod box and have not seen behavior like this on that
OS... But, I am also not running this exact code there since I can not
verify if it is working or not!

Thanks for any suggestions (I'm starting to look around for Rod
Serling...).

Here is a snippet of the code (please tell me if you need to see all of
it) - I am leaving in the debug messages (I never get to 4a and session
reports that it is not null):

  public static void sendMessage(String to, String cc, String bcc,
String from, String subject,  String msgText, MimeBodyPart[] multiMsg,
boolean debug, LogWriter log) throws IOException
  {
System.out.println("Starting send message...");
    // If no log is supplied, create one.
    boolean createdLocally = false;
    if (log == null)
    {
      createdLocally = true;
      log = sendlog;
    }
    try
    {
System.out.println("1...");
      // create some properties and get the default Session
      Properties props = new Properties();
      props.put("mail.smtp.host",
Settings.get(SettingsTypes.MailTypes.SMTP_HOST.toString()));
      if (debug)
      {
        props.put("mail.debug", "true");
      }

System.out.println("2...");
      // Log the e-mail.
      log.println("[ " + new Date().toString() + " ]");
      log.println("Subject: " + subject);
      if (to != null)
      {
        log.println("  To:  " + to);
      }
      if (cc != null)
      {
        log.println("  CC:  " + cc);
      }
      if (bcc != null)
      {
        log.println("  BCC: " + bcc);
      }
System.out.println("3...");

//      Session session = Session.getDefaultInstance(props, null);
      javax.mail.Session session = javax.mail.Session.getInstance(props,
null);
System.out.println("3a...");
if (session == null)
{
System.out.println("3b (SESSION IS NULL)...");
}
else
{
System.out.println("3b (SESSION IS NOT NULL)...");
}
      session.setDebug(debug);
System.out.println("3c...");

      try
      {
System.out.println("4...");
        // Create a message
        Message msg = new MimeMessage(session);

System.out.println("4a...:" + from);
        // From e-mail address.
        msg.setFrom(new InternetAddress(from));

... Please tell me if you need to see the rest of the code...

Error: 500

Location: /scifiguys/servlet/NewsletterController

Internal Servlet Error:

java.lang.NullPointerException
        at com.scifiguys.util.Sendmail.sendMessage(Sendmail.java,
Compiled Code)
        at
com.scifiguys.util.Sendmail.sendPredefinedEmail(Sendmail.java, Compiled
Code)
        at
com.scifiguys.NewsletterController.runNewsletter(NewsletterController.java,
Compiled Code)
        at
com.scifiguys.NewsletterController.process(NewsletterController.java,
Compiled Code)
        at
com.scifiguys.util.BaseHttpServlet.doGet(BaseHttpServlet.java:60)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:748)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java,
Compiled Code)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:597)

        at
org.apache.tomcat.servlets.InvokerServlet.service(InvokerServlet.java:257)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java,
Compiled Code)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
        at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:156)

        at
org.apache.tomcat.service.TcpWorkerThread.run(PoolTcpEndpoint.java,Compiled
Code)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java,
Compiled Code)
        at java.lang.Thread.run(Thread.java:479)

I have (using System.out.println()'s) traced the source of the exception
to the creation of the MimeMessage object (and verified that the session
is not null).

Allen