This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: FYI: Win32 InetAddress fix (really)


David Daney wrote:
> Andrew Haley wrote:
> > David Daney writes:
> > > Gary Benson wrote:
> > > > +    catch (UnknownHostException e)
> > > > +      {
> > > > +	throw new RuntimeException("should never happen", e);
> > > > +      }
> > > 
> > > Would it be better to throw an InternalError here rather than
> > > RuntimeException?  If it truly should never happen then it would
> > > be an InternalError if it did.  If it can happen, then it should
> > > be of some type the describes the problem.
> > 
> > AFAICR this is the kind of thing that happens if the IP address of
> > the loopback interface doesn't have a resolvable name,
> 
> I guess in this specific case it does not really matter as
> it is in a static initializer and the result would be an
> ExceptionInInitiazerError either way.
> 
> But in general I don't like the use RuntimeException.  It makes me
> think that we were too lazy to figure out what to do and took the
> easy (but inelegant and probably incorrect) way out by circumventing
> java's checked exception requirements.

The only time getByAddress() throws an UnknownHostException is when
the array of bytes you pass it is is neither 4 or 16 bytes long (for
IPv4 and IPv6 addresses respectively).  And since we're calling it as
getByAddress(new byte[] {127, 0, 0, 1}) it really should never happen.

I specifically didn't use InternalError in this case because its
javadoc says it's thrown to indicate an error in the VM (which I took
to mean the bytecode interpreter) and therefore that InternalError was
something that should only be thrown by the VM.  But, I suppose in
this case the only way this code could be reached is if the VM is
broken, so...

(The ultimate solution would be to have getByAddress throw an
IllegalArgumentException when it's passed an address array of
the wrong length, but that's not something we get to fix :/)

I'll make it InternalError in Classpath so it gets picked up when
I commit the remainder of the InetAddress merge.

Cheers,
Gary


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]