Write to file only in debug

J

jny0

Hi,

I have a problem where my code will write to a file when I'm stepping
throught the code in debug, but won't when I run it properly. The
really wierd thing is, that code which I wrote two weeks ago, and
which did work then, has also stopped working. I've always had this
problem when writing code for an applet, but this is just a piece of
normal text based code.

Any ideas?

Regards,
JNY0
 
A

Andreas Leitgeb

jny0 said:
I have a problem where my code will write to a file when I'm stepping
throught the code in debug, but won't when I run it properly. The
really wierd thing is, that code which I wrote two weeks ago, and
which did work then, has also stopped working. I've always had this
problem when writing code for an applet, but this is just a piece of
normal text based code.

Just blind guessing:
A misuse of "assert"? e.g.: assert myMethodToWriteToFile();

in the debugger, asserts are active so your code is run.
in a normal build/run asserts are disabled, and that means
not just the checking, but also evaluation of the assert-
expression (the call to "myMethodToWriteToFile()") is skipped.
 
J

jny0

Hi Andreas,

Here's the call I use:
OutputToFile(iGenerationCtr, dPermNegScore, fFile);

....and here's the method.
private static boolean OutputToFile(int iGenerationCtr, double
dPermNegScore, File fFile){

try
{
String sPermutationString = "";
BufferedWriter out = new BufferedWriter(new FileWriter(fFile,
true));
out.write(Integer.toString(iGenerationCtr)
+",");
out.write(sPermutationString);
out.write((Double.toString(dPermNegScore)));
out.write("\n");
out.close
();
}
catch (Exception e)
{
System.out.println("Error Writing to File " + e.getMessage
());
}
return true;
}

How would I implement code which would activate an assert? How would
this code have stopped working, when it was working aweek ago?

Regards,
JNY0
 
A

Andreas Leitgeb

jny0 said:
Hi Andreas,
Here's the call I use:
OutputToFile(iGenerationCtr, dPermNegScore, fFile);

...and here's the method.
private static boolean OutputToFile(int iGenerationCtr, double
[...]
}

Obviously no "assert" in this part.
Is your entire code completely free of any "assert" statement?

If any part (not just the immediate caller of OutputToFile) of
your code has "assert" with a method call, examine that closer.

assert is a very likely cause for your symptoms, but it isn't the
only possible one. e.g. Perhaps the code you compile and run is
not the same as the one you run in the debugger, or you do incre-
mental builds and it missed on some dependency that turns out
to be relevant.
How would I implement code which would activate an assert? How would
this code have stopped working, when it was working aweek ago?

Well, *something* must have changed since two weeks ago.
perhaps you inadvertedly added some bug (e.g. added an "assert")
or changed the compile-scripts (ant?) to the effect of switching
off assertions. Or maybe some playing in your IDE's configuration
caused your project to be build differently than before...

PS: About your code sample: the are guidelines to Java programming
that I really encourage you to follow: Firstly, don't start
method names with capital letters, and secondly don't
"catch(Exception ...)". Rather catch those specific Exceptions
that you really expect (e.g. IOException, ...).
 
N

Nigel Wade

jny0 said:
Hi,

I have a problem where my code will write to a file when I'm stepping
throught the code in debug, but won't when I run it properly. The
really wierd thing is, that code which I wrote two weeks ago, and
which did work then, has also stopped working. I've always had this
problem when writing code for an applet, but this is just a piece of
normal text based code.

Any ideas?

Regards,
JNY0

Are you absolutely certain that the class files being executed when you "run it
properly" (presumably outside your IDE) are exactly the same as the class files
your IDE is single-stepping through? Some IDEs don't re-build
the "distribution" class/jar files unless you explicitly tell them to.
 
J

jny0

Just downloaded a new version of NetBeans, and the problem seems to be
sorted. Must have been a config setting I changed at some point.
I've searched, but can find no reference to it?

At least the problem's sorted.

Cheers,
JNY0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top