[BLUEJ-56] Trouble caused by System.out.close(), because VM not re-initialized.
I ran into the following (minor) problem, but I thought I'd pass it along to document, as it appeared to be a more major problem at first glance.
I was preparing to use an assignment in BlueJ that was modified from an outside source. In its original form it sent output to a file (or to System.out by default), and it explicitly included a call to output.close(), irregardless of whether 'output' was indeed a file or System.out. In a normal environment, this call to System.out.close() was fine, as the program would soon exit, and the VM would be restarted if the program were rerun.
In BlueJ, this was another story. It ran fine the first time, but when I reran main(), it appeared as if nothing happened. Upon further inspection, the repeated runs were executing fine internally, but the System.out.close() call from an earlier run had disabled all output.
I imagine this is due to the design decision in which the VM is not automatically restart in BlueJ, and thus closing System.out causes this effect. If I explicitly reset the VM between runs, everything is fine (though this is certainly not a convenient way to operate).
Of course, now that I've recognized the problem, I've simply updated the code so as not to close the output if System.out. Obviously, this would have been a better practice in the first case, but the point is that there is code out there like the one that I found which does not follows such a practice. BlueJ gets the apparent blame when this flaw is manifested.
The particular example program I was using is immaterial, but I'll attach a tarfile in a moment to include it to this bug report, in case it helps.
------- Comment BLUEJ-1 From Michael Goldwasser 2004-03-03 05:02:34 [reply] -------
Created an attachment (id=14) [details] sample project (tarfile)
------- Comment BLUEJ-2 From Michael Goldwasser 2004-03-03 05:04:41 [reply] -------
(From update of attachment 14 [details]) run main with args:
{"500","6","input/aesopshort.txt"}
------- Comment BLUEJ-3 From Michael K?lling 2004-05-03 17:28:05 [reply] -------
We have to discuss this. I am not sure at this stage whether this is not exactly as it should be: if you close a stream, you cannot write to it anymore...
Needs discussion, and decision.
------- Comment BLUEJ-4 From Michael K?lling 2004-08-19 00:07:16 [reply] ------
Okay, I think the behaviour should be: VM should restart automatically if public static void main is called (but not on oher calls).
This resets all static context, as users expect for standard executions (but not for individual methods executions).
Issue metadata
- Issue type: Bug
- Priority: Low
- Fix versions: 3.0.0