Saturday, November 19, 2011
Java 7 behaves differently on InetAddress.getHostName()
On my Mac, if I execute the following code in Java 6:
Solution ?
Add two entries to my /etc/hosts:
I got:System.out.println(InetAddress.getLocalHost().getHostName());
But when run in Java 7, I got:5855pns93223
This causes problem with some existing Java mail code, with exception like:5855pns93223.nznmba.com
This isn't good for unit testing when I need to run them locally.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)
Solution ?
Add two entries to my /etc/hosts:
A hack, I know, but a quick fix at least for now :)127.0.0.1 5855pns93223
127.0.0.1 5855pns93223.nznmba.com