Here is a convenient download for this Java program:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class Bug {
public static void main(String[] args) throws IOException {
File foo = new File("foo");
for (int i = 0; i < 100; i++) {
final File bazf = new File(foo, "baz");
bazf.delete();
foo.delete();
foo.mkdir();
OutputStream out;
try {
out = new FileOutputStream(new File(foo, "baz"));
} catch (Throwable t) {
throw new Error("Lost in iteration " + i, t);
}
out.close();
}
}
}
The typical stack trace when you run it is:
Exception in thread "main" java.lang.Error: Lost in iteration 56 at Bug.main(Bug.java:19) Caused by: java.io.FileNotFoundException: foo\baz (Access is denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream. (Unknown Source) at Bug.main(Bug.java:17)
Here is a convenient download for esentially the same program written in Python:
import os
import os.path
for i in range(100):
if os.path.exists("foo/baz"):
os.remove("foo/baz")
if os.path.exists("foo"):
os.rmdir("foo")
try:
os.mkdir("foo")
file("foo/baz", "w").close()
except:
print "lost in iteration %r" % (i,)
raise
The typical output is:
lost in iteration 35
Traceback (most recent call last):
File "bug.py", line 9, in ?
os.mkdir("foo")
OSError: [Errno 13] Permission denied: 'foo'