gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnu-arch-users] Re: [OT] Java is fun!


From: Tom Lord
Subject: Re: [Gnu-arch-users] Re: [OT] Java is fun!
Date: Thu, 23 Oct 2003 10:14:16 -0700 (PDT)


    > From: Momchil Velikov <address@hidden>

    [relinking a java program can silently break exceptions contracts]

    > This is relevant to probably _any_ language, in particular C:

    > Consider changing [1]

    >         struct dirent *readdir(DIR *dir);

    > to

    >         int readdir (DIR *DIRSTREAM, struct dirent *ENTRY,
    >                      struct dirent **RESULT);

Yes, that's true of typical implementations of C but there's some
differences from the language design perspective:

1) C doesn't _require_ (does it?) that the linker not perform that
   type check.  I could define an object format and linker that would
   perform it and still have a standard-conforming C implementation.
   
   Java _requires_ that the linker not perform the exception check.
   There isn't even enough information in class files to permit
   a link-time check, and, unlike C, a single standard "object file"
   format is an important part of how the language is supposed to be
   used. 


2) In C, we fully expect that linked in code has pretty much free
   reign and that the code it's linked into can not control what it
   does.

   In Java, we have the opposite expectation.

   Now to be sure, it is still _possible_ to write Java code which is
   robust against the exception-checking hole, but to do so means that
   you have to `catch (Throwable ...)' whenever you call outside your
   package.   If you then want to rethrow some subset of "unexpected" 
   exceptions, you have to use constructs other than `catch' to
   discriminate among the exception types.   Practices like that have 
   been explicitly denounced by Java fans on the list who say that
   they are poor practice in Java.


One amusing observation is that, given the other rules (about
reachable code and so forth), if the idea of an unchecked exception
were dropped from Java, it would be essentially impossible to write
safe code in Java, at least for some of its more famous target
environments.


-t




reply via email to

[Prev in Thread] Current Thread [Next in Thread]