[jcifs] Problem with jcifs.UniAddress.isValidDnsName(String)

Michael B Allen mba2000 at ioplex.com
Fri Oct 7 20:11:58 GMT 2005

On Fri, 7 Oct 2005 14:37:20 -0400
Michael B Allen <mba2000 at ioplex.com> wrote:

> > I'm wondering if the method actually serves any purpose except to be
> > broken. Its only reference is:
> > 
> >     if( isValidDnsName( hostname ) == false ) {
> >         throw new UnknownHostException( hostname );
> >     }
> >     addr = InetAddress.getByName( hostname );
> > 
> > Consider that InetAddress.getByName(hostname) throws the same
> > UnknownHostException as the 'if' statement, and is more effective at
> > detecting invalid hostnames than any method call or regex. Could the
> > method and call be removed entirely?
> Clearly this check is designed to subvert the DNS lookup because
> it may *succeed* and then the resolver will not try the next lookup
> method. Unfortunately I don't understand the code comment and I don't
> recall what the original problem was.

I just remembered why this is in here. You can have a NetBIOS hostname
like '1' and I *think* InetAddress.getByName() would incorrectly interpret
this as an IP address and NOT throw an UnknownHostException (at the time
I checked, probably Java 1.2 days). So this code tried to dodge this
in the case where resolvOrder had DNS before NBT. Otherwise getByName
would return a bogus InetAddress and the loop would not continue on to
try NbtAddress.getByName().

So it's Sun's fault not me!


More information about the jcifs mailing list