Skip to content

Commit

Permalink
Minor fix to resource management; make sure that the file property is…
Browse files Browse the repository at this point in the history
… properly nulled when setFile(null) is called
  • Loading branch information
dmlloyd committed Apr 16, 2012
1 parent 40523dd commit 84f028a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/org/jboss/logmanager/handlers/FileHandler.java
Expand Up @@ -142,6 +142,7 @@ public void setAppend(final boolean append) {
public void setFile(File file) throws FileNotFoundException { public void setFile(File file) throws FileNotFoundException {
synchronized (outputLock) { synchronized (outputLock) {
if (file == null) { if (file == null) {
this.file = null;
setOutputStream(null); setOutputStream(null);
return; return;
} }
Expand All @@ -150,11 +151,18 @@ public void setFile(File file) throws FileNotFoundException {
parentFile.mkdirs(); parentFile.mkdirs();
} }
boolean ok = false; boolean ok = false;
final OutputStream fos = new BufferedOutputStream(new FileOutputStream(file, append)); final FileOutputStream fos = new FileOutputStream(file, append);
try { try {
setOutputStream(fos); final OutputStream bos = new BufferedOutputStream(fos);
this.file = file; try {
ok = true; setOutputStream(bos);
this.file = file;
ok = true;
} finally {
if (! ok) {
safeClose(bos);
}
}
} finally { } finally {
if (! ok) { if (! ok) {
safeClose(fos); safeClose(fos);
Expand Down

0 comments on commit 84f028a

Please sign in to comment.