When using an older version of JavaMail, 1.4, with a JVM running with assertions-enabled -ea
, JavaMail always throws an AssertionError
on connection to an SMTP server:
Caused by: java.lang.AssertionError
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1578)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1369)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:251)
The AssertionError
is completely unexpected, I would expect the connection to work, and it does work fine without JVM assertions-enabled.
Can anything be done to resolve this error short of giving-up running with assertions?
You need to upgrade to a newer or current JavaMail. This looks like an old bug which has since been fixed in the JavaMail reference implementation, with the fix post version 1.4.
Reviewing SMTPTransport source code , it performs a lot of assertions checking that the code is holding the current monitor/lock on itself. One of the methods was missing the synchronized keyword, making this untrue, resulting in an AssertionError
, but only if assertions are explicitly enabled. It looks like the method missing the synchronization block was fixed in this revision.
The simplest course of action is to either upgrade to a newer JavaMail, or disable assertions.
See also JIRA knowledge base.