Skip to content

Commit bc7807b

Browse files
thisdudeiknewppkarwasz
authored andcommitted
Propagate synchronous action failures in RollingFileManager and FileRenameAction (#1445, #1549)
1 parent 419fc5e commit bc7807b

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameActionTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public void testRename1() throws Exception {
4545

4646
final File dest = new File(tempDir, "newFile.log");
4747
final FileRenameAction action = new FileRenameAction(file, dest, false);
48-
action.execute();
48+
boolean renameResult = action.execute();
49+
assertTrue(renameResult, "Rename action returned false");
4950
assertTrue(dest.exists(), "Renamed file does not exist");
5051
assertFalse(file.exists(), "Old file exists");
5152
}
@@ -59,7 +60,8 @@ public void testEmpty() throws Exception {
5960
assertTrue(file.exists(), "File to rename does not exist");
6061
final File dest = new File(tempDir, "newFile.log");
6162
final FileRenameAction action = new FileRenameAction(file, dest, false);
62-
action.execute();
63+
boolean renameResult = action.execute();
64+
assertTrue(renameResult, "Rename action returned false");
6365
assertFalse(dest.exists(), "Renamed file should not exist");
6466
assertFalse(file.exists(), "Old file still exists");
6567
}
@@ -73,7 +75,8 @@ public void testRenameEmpty() throws Exception {
7375
assertTrue(file.exists(), "File to rename does not exist");
7476
final File dest = new File(tempDir, "newFile.log");
7577
final FileRenameAction action = new FileRenameAction(file, dest, true);
76-
action.execute();
78+
boolean renameResult = action.execute();
79+
assertTrue(renameResult, "Rename action returned false");
7780
assertTrue(dest.exists(), "Renamed file should exist");
7881
assertFalse(file.exists(), "Old file still exists");
7982
}
@@ -89,7 +92,8 @@ public void testNoParent() throws Exception {
8992

9093
final File dest = new File(tempDir, "newFile.log");
9194
final FileRenameAction action = new FileRenameAction(file, dest, false);
92-
action.execute();
95+
boolean renameResult = action.execute();
96+
assertTrue(renameResult, "Rename action returned false");
9397
assertTrue(dest.exists(), "Renamed file does not exist");
9498
assertFalse(file.exists(), "Old file exists");
9599
}

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ private boolean rollover(final RolloverStrategy strategy) {
546546
asyncExecutor.execute(new AsyncAction(descriptor.getAsynchronous(), this));
547547
releaseRequired = false;
548548
}
549-
return true;
549+
return success;
550550
}
551551
return false;
552552
} finally {

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/FileRenameAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public static boolean execute(final File source, final File destination, final b
191191
}
192192
} else {
193193
try {
194-
source.delete();
194+
return source.delete();
195195
} catch (final Exception exDelete) {
196196
LOGGER.error(
197197
"Unable to delete empty file {}: {} {}",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to you under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xmlns="http://logging.apache.org/log4j/changelog"
20+
xsi:schemaLocation="http://logging.apache.org/log4j/changelog https://logging.apache.org/log4j/changelog-0.1.1.xsd"
21+
type="fixed">
22+
<issue id="1445" link="https://github.com/apache/logging-log4j2/issues/1445"/>
23+
<author id="thisdudeiknew" name="Timothy Pfeifer"/>
24+
<description format="asciidoc">
25+
Fixed `RollingFileManager` to propagate failed synchronous actions correctly.
26+
</description>
27+
</entry>

0 commit comments

Comments
 (0)