Skip to content
Browse files

Minor fix to resource management; make sure that the file property is…

… properly nulled when setFile(null) is called
  • Loading branch information...
1 parent 40523dd commit 84f028a57e0ae5ec55ae6ae63a29fdc1ec26399f @dmlloyd dmlloyd committed Apr 16, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/main/java/org/jboss/logmanager/handlers/FileHandler.java
View
16 src/main/java/org/jboss/logmanager/handlers/FileHandler.java
@@ -142,6 +142,7 @@ public void setAppend(final boolean append) {
public void setFile(File file) throws FileNotFoundException {
synchronized (outputLock) {
if (file == null) {
+ this.file = null;
setOutputStream(null);
return;
}
@@ -150,11 +151,18 @@ public void setFile(File file) throws FileNotFoundException {
parentFile.mkdirs();
}
boolean ok = false;
- final OutputStream fos = new BufferedOutputStream(new FileOutputStream(file, append));
+ final FileOutputStream fos = new FileOutputStream(file, append);
try {
- setOutputStream(fos);
- this.file = file;
- ok = true;
+ final OutputStream bos = new BufferedOutputStream(fos);
+ try {
+ setOutputStream(bos);
+ this.file = file;
+ ok = true;
+ } finally {
+ if (! ok) {
+ safeClose(bos);
+ }
+ }
} finally {
if (! ok) {
safeClose(fos);

0 comments on commit 84f028a

Please sign in to comment.
Something went wrong with that request. Please try again.