Discussion:
NullpointerException when closing folder
Wolfgang Beikircher
2009-03-20 11:14:24 UTC
Permalink
Hi there!

I'm using JavaMail 1.4.2 and get an NullPointerException when I try to
close a folder. This happens only after some hours of run time of my
application. Therefore, I think it has something to do with the
connection timeout to the server.

This is the error stack:

Caused by: java.lang.NullPointerException
at com.sun.mail.iap.Protocol.command(Protocol.java:324)
at
com.sun.mail.imap.protocol.IMAPProtocol.logout(IMAPProtocol.java:311)
at com.sun.mail.imap.IMAPStore.releaseProtocol(IMAPStore.java:944)
at com.sun.mail.imap.IMAPFolder.releaseProtocol(IMAPFolder.java:2666)
at com.sun.mail.imap.IMAPFolder.cleanup(IMAPFolder.java:1143)
at com.sun.mail.imap.IMAPFolder.close(IMAPFolder.java:1132)
at com.sun.mail.imap.IMAPFolder.close(IMAPFolder.java:1055)
at com.sun.mail.imap.IMAPStore.cleanup(IMAPStore.java:1289)
at com.sun.mail.imap.IMAPStore.handleResponse(IMAPStore.java:1509)
at com.sun.mail.iap.Protocol.notifyResponseHandlers(Protocol.java:216)
at
com.sun.mail.imap.protocol.IMAPProtocol.logout(IMAPProtocol.java:316)
at com.sun.mail.imap.IMAPStore.close(IMAPStore.java:1217)
at
org.zimbra.exchange.email.transport.ImapMailServerWrapper.releaseConnection(ImapMailServerWrapper.java:129)
... 7 more


Could someone propose a workaround?

Thanks.

Sincerely,
Wolfgang Beikircher

===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Bill Shannon
2009-03-20 18:39:57 UTC
Permalink
Post by Wolfgang Beikircher
Hi there!
I'm using JavaMail 1.4.2 and get an NullPointerException when I try to
close a folder. This happens only after some hours of run time of my
application. Therefore, I think it has something to do with the
connection timeout to the server.
Caused by: java.lang.NullPointerException
at com.sun.mail.iap.Protocol.command(Protocol.java:324)
at
com.sun.mail.imap.protocol.IMAPProtocol.logout(IMAPProtocol.java:311)
at com.sun.mail.imap.IMAPStore.releaseProtocol(IMAPStore.java:944)
at com.sun.mail.imap.IMAPFolder.releaseProtocol(IMAPFolder.java:2666)
at com.sun.mail.imap.IMAPFolder.cleanup(IMAPFolder.java:1143)
at com.sun.mail.imap.IMAPFolder.close(IMAPFolder.java:1132)
at com.sun.mail.imap.IMAPFolder.close(IMAPFolder.java:1055)
at com.sun.mail.imap.IMAPStore.cleanup(IMAPStore.java:1289)
at com.sun.mail.imap.IMAPStore.handleResponse(IMAPStore.java:1509)
at com.sun.mail.iap.Protocol.notifyResponseHandlers(Protocol.java:216)
at
com.sun.mail.imap.protocol.IMAPProtocol.logout(IMAPProtocol.java:316)
at com.sun.mail.imap.IMAPStore.close(IMAPStore.java:1217)
at
org.zimbra.exchange.email.transport.ImapMailServerWrapper.releaseConnection(ImapMailServerWrapper.java:129)
... 7 more
You may be right about a timeout causing this problem, but I'm
struggling to see why a timeout would cause this NullPointerException.

The code in Protocol.java is:

public synchronized Response[] command(String command, Argument args) {
Vector v = new Vector();
boolean done = false;
String tag = null;
Response r = null;

// write the command
try {
tag = writeCommand(command, args);
} catch (LiteralException lex) {
v.addElement(lex.getResponse());
done = true;
} catch (Exception ex) {
// Convert this into a BYE response
v.addElement(Response.byeResponse(ex));
done = true;
}

while (!done) {
try {
r = readResponse();
} catch (IOException ioex) {
// convert this into a BYE response
r = Response.byeResponse(ioex);
} catch (ProtocolException pex) {
continue; // skip this response
}

v.addElement(r);

if (r.isBYE()) // shouldn't wait for command completion response
done = true;

// If this is a matching command completion response, we are done
if (r.isTagged() && r.getTag().equals(tag))
done = true;
}

Response[] responses = new Response[v.size()];
v.copyInto(responses); // <---- line 324
timestamp = System.currentTimeMillis();
return responses;
}

"v" can't be null. "responses" can't be null.
Even if one of the elements in v is null (which shouldn't happen),
that wouldn't cause the NullPointerException.

What am I missing?

===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Wolfgang Beikircher
2009-03-23 09:35:34 UTC
Permalink
Hi Bill!

Now I saw what the problem is: in principle there is only one
possibility to cause a NullPointerException => if you run out of memory.
And exactly that happend. The reason why I don't figured it out earlier
is because I don't checked the catalina.out file of Tomcat. Anyway, I
corrected now my source code in the way, that I transfer smaller chunks
of data.

Sincerely,
Wolfgang
Post by Bill Shannon
Post by Wolfgang Beikircher
Hi there!
I'm using JavaMail 1.4.2 and get an NullPointerException when I try to
close a folder. This happens only after some hours of run time of my
application. Therefore, I think it has something to do with the
connection timeout to the server.
Caused by: java.lang.NullPointerException
at com.sun.mail.iap.Protocol.command(Protocol.java:324)
at
com.sun.mail.imap.protocol.IMAPProtocol.logout(IMAPProtocol.java:311)
at com.sun.mail.imap.IMAPStore.releaseProtocol(IMAPStore.java:944)
at com.sun.mail.imap.IMAPFolder.releaseProtocol(IMAPFolder.java:2666)
at com.sun.mail.imap.IMAPFolder.cleanup(IMAPFolder.java:1143)
at com.sun.mail.imap.IMAPFolder.close(IMAPFolder.java:1132)
at com.sun.mail.imap.IMAPFolder.close(IMAPFolder.java:1055)
at com.sun.mail.imap.IMAPStore.cleanup(IMAPStore.java:1289)
at com.sun.mail.imap.IMAPStore.handleResponse(IMAPStore.java:1509)
at com.sun.mail.iap.Protocol.notifyResponseHandlers(Protocol.java:216)
at
com.sun.mail.imap.protocol.IMAPProtocol.logout(IMAPProtocol.java:316)
at com.sun.mail.imap.IMAPStore.close(IMAPStore.java:1217)
at
org.zimbra.exchange.email.transport.ImapMailServerWrapper.releaseConnection(ImapMailServerWrapper.java:129)
... 7 more
You may be right about a timeout causing this problem, but I'm
struggling to see why a timeout would cause this NullPointerException.
public synchronized Response[] command(String command, Argument args) {
Vector v = new Vector();
boolean done = false;
String tag = null;
Response r = null;
// write the command
try {
tag = writeCommand(command, args);
} catch (LiteralException lex) {
v.addElement(lex.getResponse());
done = true;
} catch (Exception ex) {
// Convert this into a BYE response
v.addElement(Response.byeResponse(ex));
done = true;
}
while (!done) {
try {
r = readResponse();
} catch (IOException ioex) {
// convert this into a BYE response
r = Response.byeResponse(ioex);
} catch (ProtocolException pex) {
continue; // skip this response
}
v.addElement(r);
if (r.isBYE()) // shouldn't wait for command completion response
done = true;
// If this is a matching command completion response, we are done
if (r.isTagged() && r.getTag().equals(tag))
done = true;
}
Response[] responses = new Response[v.size()];
v.copyInto(responses); // <---- line 324
timestamp = System.currentTimeMillis();
return responses;
}
"v" can't be null. "responses" can't be null.
Even if one of the elements in v is null (which shouldn't happen),
that wouldn't cause the NullPointerException.
What am I missing?
===========================================================================
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Bill Shannon
2009-03-23 16:54:13 UTC
Permalink
Post by Wolfgang Beikircher
Hi Bill!
Now I saw what the problem is: in principle there is only one
possibility to cause a NullPointerException => if you run out of memory.
And exactly that happend. The reason why I don't figured it out earlier
is because I don't checked the catalina.out file of Tomcat. Anyway, I
corrected now my source code in the way, that I transfer smaller chunks
of data.
That would explain it! Thanks for letting me know.

===========================================================================
To unsubscribe, send email to ***@java.sun.com and include in the body
of the message "signoff JAVAMAIL-INTEREST". For general help, send email to
***@java.sun.com and include in the body of the message "help".
Continue reading on narkive:
Loading...