Bug in Jitter

Laurent Bossavit morendil at micronet.fr
Tue Jul 7 11:15:28 PDT 1998


> Can one resurrect a thread that died out a year ago?

Now that would be a nice example of persistence. ;)

> I also think that the example by Gary Howland a year ago, where a local
> variable that contained a value was clobbered might not be as frequent
> as the example encountered by Laurent in the Java WebServer, where the
> local variable in question contained a return address.

You probably mean 'not as serious' - seems to me that local variables 
are used more frequently, on the whole, than return addresses... But 
I would feel seriously concerned about Java if I could not rely on a
local variable keeping its value; whereas I can probably live with a
principle of 'avoid throwing an exception from within a finally {}'.

Then again my test case voluntarily obscured the practical 
aspect in favor of demonstrating the bug. The actual code went 
something like this :

  InputStream inputstream = null;
  try {
    try {
      // do some operations which might result in getting an input 
      // stream
      String firstLine = inputstream.readline();
      // do further operations which might cause an exception
      return firstLine;
    }
    catch (IOException e) {}
    return "Failed to read file";
  }
  finally {
    try {
      inputsream.close();
    }
    catch (Exception e) {}
  }

 This seems to have become a common enough Java programming idiom 
that the problem is IMHO a serious cause for concern.

> (*) I've been thinking about why people might program like this.
> I know there is a school of thinking that says to use exceptions to
> detect abnormal conditions, possibly speeding up the normal case.

I don't see them as a possible speedup (as you mention, the cost, 
performance wise, of a try..catch block is VM-dependent) as much
as a compelling way of doing 'programming-by-contract'. You keep
operations that correspond to contractual expectations within a try {}
block and handle contract violations in the catch {}. So rather than
using exceptions to 'detect' abnormal conditions, you use them to 
_define_ what conditions you consider to be abnormal.


=====================================================
Laurent Bossavit
NetDIVE Paris offices                      (o o)
--------------------------------     -oOO--( )--OOo-
http://www.netdive.com/
NetDIVE: the leader in virtual meeting technology
=====================================================


More information about the kaffe mailing list