2011
03.11
03.11
I came across an interesting error when starting an ActiveMQ client the other day:
Could not connect to broker URL: tcp://activemq_qa.company.com:35000. Reason: java.lang.IllegalArgumentException: port out of range:-1
It turns out to be related to the DNS: java.net.URI.getHost() returns null if the DNS contains an underscore. The following JRuby snippet demonstrates it:
pierre % cat dns.rb require "java" include_class "java.net.URI" INVALID_URI = "tcp://dns_foo.company.com:35000" VALID_URI = "tcp://dns-foo.company.com:35000" u = URI.new(INVALID_URI) puts u.getHost, u.getPort v = URI.new(VALID_URI) puts v.getHost, v.getPort pierre % jruby dns.rb nil -1 dns-foo.company.com 35000
Hostnames are supposed to contain only letters, numbers and the hyphen. From rfc952:
1. A “name” (Net, Host, Gateway, or Domain name) is a text string up
to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus
sign (-), and period (.).
I just wished the error was a bit more meaningful.

Sadly, this restriction comes from an historical misunderstanding of RFC952 that was not supposed to apply to DNS.
Section 11 of RFC2181 “Clarifications to the DNS Specification” tried to clarify it. But it was too late. Records that include domain names are not subject to RFC952.
Thank you for the full explanation!
Thanks for this page. Most helpful.