Collapse two levels of try now that we use a try-with-resources. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/dca3e56b Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/dca3e56b Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/dca3e56b
Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure Commit: dca3e56b9ed2ab1ef7033e29d3e9bda64df87ce6 Parents: 1a49a34 Author: Gary Gregory <ggreg...@apache.org> Authored: Sat Aug 6 12:08:26 2016 -0700 Committer: Gary Gregory <ggreg...@apache.org> Committed: Sat Aug 6 12:08:26 2016 -0700 ---------------------------------------------------------------------- .../log4j/core/appender/FileManager.java | 22 +++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dca3e56b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java index 542edbf..af10d25 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java @@ -90,21 +90,19 @@ public class FileManager extends OutputStreamManager { if (isLocking) { final FileChannel channel = ((FileOutputStream) getOutputStream()).getChannel(); - try { - /* Lock the whole file. This could be optimized to only lock from the current file - position. Note that locking may be advisory on some systems and mandatory on others, - so locking just from the current position would allow reading on systems where - locking is mandatory. Also, Java 6 will throw an exception if the region of the - file is already locked by another FileChannel in the same JVM. Hopefully, that will - be avoided since every file should have a single file manager - unless two different - files strings are configured that somehow map to the same file.*/ - try (final FileLock lock = channel.lock(0, Long.MAX_VALUE, false)) { - super.write(bytes, offset, length, immediateFlush); - } + /* + * Lock the whole file. This could be optimized to only lock from the current file position. Note that + * locking may be advisory on some systems and mandatory on others, so locking just from the current + * position would allow reading on systems where locking is mandatory. Also, Java 6 will throw an exception + * if the region of the file is already locked by another FileChannel in the same JVM. Hopefully, that will + * be avoided since every file should have a single file manager - unless two different files strings are + * configured that somehow map to the same file. + */ + try (final FileLock lock = channel.lock(0, Long.MAX_VALUE, false)) { + super.write(bytes, offset, length, immediateFlush); } catch (final IOException ex) { throw new AppenderLoggingException("Unable to obtain lock on " + getName(), ex); } - } else { super.write(bytes, offset, length, immediateFlush); }