'Programming by Coincidence' Excercise: Java File Writer

Posted by Tapas on Stack Overflow See other posts from Stack Overflow or by Tapas
Published on 2010-04-08T22:26:51Z Indexed on 2010/04/08 22:33 UTC
Read the original article Hit count: 397

Filed under:
|
|

I just read the article Programming by Coincidence. At the end of the page there are excercises. A few code fragments that are cases of "programming by coincidence". But I cant figure out the error in this piece:

This code comes from a general-purpose Java tracing suite. The function writes a string to a log file. It passes its unit test, but fails when one of the Web developers uses it. What coincidence does it rely on?

  public static void debug(String s) throws IOException {
    FileWriter fw = new FileWriter("debug.log", true);
    fw.write(s);
    fw.flush();
    fw.close();
  }

What is wrong about this?

© Stack Overflow or respective owner

Related posts about java

Related posts about source-code