SBT application reload invariably fails when program uses javax.mail

I have the same problem in both Play 2.3 and 2.6. If the program imports from javax.mail, SBT reload invariably crashes with

play.sbt.PlayExceptions$UnexpectedException: Unexpected exception[ClassCastException: 
java.lang.Integer cannot be cast to java.lang.String]
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
	at org.apache.ivy.core.settings.IvySettings.addAllVariables(
	at org.apache.ivy.core.settings.IvySettings.addAllVariables(
	at org.apache.ivy.core.settings.IvySettings.addSystemProperties(
	at org.apache.ivy.core.settings.IvySettings.<init>(
	at org.apache.ivy.core.settings.IvySettings.<init>(

After this I have to stop sbt and restart from the shell.

If I comment out the javax.mail references, there is no exception. I have tried different sources for javax.mail in the depencies section in build.sbt:

"javax.mail" % "mail" % "1.4.7",
"javax.mail" % "javax.mail-api" % "1.6.2",
"com.sun.mail" % "javax.mail" % "1.6.2"

with the same exception as result. This is a major annoyance, having to restart everything hard after every code change. Is there anything I can do?

Looks like javax.mail sets System properties which are not type of String (just a guess).

However, not being able to handle System properties of types other than String was a bug in Apache Ant Ivy, which got fixed already:

The problem now is that sbt is using a forked Apache Ant Ivy, which isn’t up-to-date with the upstream project yet, meaning the referenced patch didn’t make it in that fork yet.

That’s why I just opened a pull request with exactly that patch:

If that pull request gets accepted it should make it into the next sbt release and your problem should be fixed.

Kind regards,

Great, thanks. I’m quite some way behind in sbt versions, so I might run into other problems on the way, but I’m happy to have finally figured this one out!

Btw, I can confirm:

		properties = System.getProperties();
		properties.put("mail.transport.protocol", "smtp");
		properties.put("mail.smtp.port", PORT);
		properties.put("mail.smtp.auth", "true");
		properties.put("mail.smtp.starttls.enable", "true");
		properties.put("mail.smtp.starttls.required", "true");

If I comment out properties.put(“mail.smtp.port”, PORT); there is no exception.

1 Like

If I comment out properties.put(“mail.smtp.port”, PORT); there is no exception.

:+1: That confirms my guess.

Can you try this workaround, making the port a String instead of an Integer?

properties.put("mail.smtp.port", "" + PORT);

Let’s see if javax mail picks that up correctly…

I can try but it will probably not work, as mail.smtp.port is supposed to be int:

That said, now that I know the problem, I can simply comment out just that line, as I actually send mail only in production.