saveJSONObject doesn't close the file #3705

Closed
PhiLhoSoft opened this Issue Aug 24, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@PhiLhoSoft

Related thread in the forum: http://forum.processing.org/two/discussion/12218/why-can-t-i-read-a-json-file-with-a-different-program-while-my-sketch-is-still-open

Problematic code:

public boolean save(File file, String options) {
  return write(PApplet.createWriter(file), options);
}

write() cannot close the writer itself (it owns to the caller) but in save(), it should manage the lifetime of the writer.
So I propose something like:

public boolean save(File file, String options) {
  PrintWriter writer = PApplet.createWriter(file);
  boolean r = write(writer, options);
  writer.close();
  return r;
}

Or, cleaner, wrap the call in a try ./ finally, as write() can throw an exception.

@benfry benfry closed this in 3deb822 Aug 24, 2015

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Aug 24, 2015

Member

Fixed for 3.0 beta 5, thanks for the report.

Member

benfry commented Aug 24, 2015

Fixed for 3.0 beta 5, thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment