tags:

views:

124

answers:

4

My project generates some text/binary files. If I run it normally, some files will have a pretty low size ( which indicates something went wrong ). If I run it from debug mode ( stepping through code ), the files will be generated correctly.

What can cause this behaviour? I'm pretty sure I don't have any unclosed files.

EDIT: I've gone through the code in a more focused way, and I've found the problem. At one point in time, the files get compressed, and this explains the decrease in size. I'm stupid :) A moderator can close this question if he sees fit.

+2  A: 

have you tried to call the compiler via commandline, or occurs this behaviour just as you build within eclipse?

Christoferw
Tried to ran it via commandline, same behaviour occurs.
Geo
+2  A: 

Is your code multithreaded? Are you trying to read something that you haven't given another thread a chance to finish constructing, which doesn't manifest when you're stepping through it?

Robert Grant
+1  A: 

Do you call some kind of "read" method, to read from a file, for example, and assume that you will always get back the number of bytes that you request?

Matthew Wilson
+3  A: 

Try adding:

System.gc();
try { Thread.sleep(4000); } catch (Exception e) {}
System.gc();

...at the end of your program. If the problem goes away then you did forget to close() a file. The above code is no solution, it is a hacky attempt to increase the likelyhood finalizers will run.

fd
Added the code. Nothing's changed.
Geo
I'd definitely be tempted to add logging/printlns to debug the problem (old school style!)
fd
...or you could try a different JRE or version of Java, you never know, it could be a bug.
fd
In fact, what is the output of java -version for the JRE you are using?
fd