Google
 
Web unafbapune.blogspot.com

Saturday, November 19, 2011

 

Java 7 behaves differently on InetAddress.getHostName()

On my Mac, if I execute the following code in Java 6:
System.out.println(InetAddress.getLocalHost().getHostName());
I got:
5855pns93223
But when run in Java 7, I got:
5855pns93223.nznmba.com
This causes problem with some existing Java mail code, with exception like:
Caused by: javax.mail.MessagingException: 501 5.0.0 HELO requires domain address
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
This isn't good for unit testing when I need to run them locally.

Solution ?

Add two entries to my /etc/hosts:
127.0.0.1 5855pns93223
127.0.0.1 5855pns93223.nznmba.com
A hack, I know, but a quick fix at least for now :)

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?