Skip to content

Commit 1b9074d

Browse files
committed
Avoid compile errors with logback if using a new target definition
1 parent 060aaee commit 1b9074d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/logging/internal/LogbackConfiguration.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private void configureLogs(String logFileName, String logLevel) {
8888
triggeringPolicy.setContext(logbackContext);
8989

9090
/*
91-
* SizeBaseTriggeringPolicy#setMaxFileSize changed between logback-core 1.1.7 and 1.1.7:
91+
* SizeBaseTriggeringPolicy#setMaxFileSize changed between logback-core 1.1.7 and 1.1.8:
9292
*
9393
* https://github.com/qos-ch/logback/blob/v_1.1.7/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicy.java
9494
*
@@ -98,19 +98,26 @@ private void configureLogs(String logFileName, String logLevel) {
9898
*
9999
* public void setMaxFileSize(FileSize aMaxFileSize)
100100
*/
101+
Exception firstTry = null;
101102
try {
102-
triggeringPolicy.setMaxFileSize(DEFAULT_PMD_LOG_MAX_FILE_SIZE);
103-
} catch (NoSuchMethodError e) {
103+
Method m = triggeringPolicy.getClass().getMethod("setMaxFileSize", String.class);
104+
m.invoke(triggeringPolicy, DEFAULT_PMD_LOG_MAX_FILE_SIZE);
105+
} catch (IllegalArgumentException | ReflectiveOperationException | SecurityException e) {
106+
firstTry = e;
107+
}
108+
109+
if (firstTry != null) {
104110
try {
105111
Method m = triggeringPolicy.getClass().getMethod("setMaxFileSize", FileSize.class);
106-
assert m != null;
107112
m.invoke(triggeringPolicy, FileSize.valueOf(DEFAULT_PMD_LOG_MAX_FILE_SIZE));
108-
} catch (IllegalArgumentException | ReflectiveOperationException | SecurityException e2) {
113+
} catch (IllegalArgumentException | ReflectiveOperationException | SecurityException e) {
109114
// relying on the default max file size
110115
System.err.println("WARNING: Unable to configure max file size for SizeBasedTriggeringPolicy.");
111116
System.err.println("Falling back to default of " + SizeBasedTriggeringPolicy.DEFAULT_MAX_FILE_SIZE + " bytes");
112-
System.err.println("Reported exception:");
113-
e2.printStackTrace();
117+
System.err.println("Reported exception on first try:");
118+
firstTry.printStackTrace();
119+
System.err.println("Reported exception on second try:");
120+
e.printStackTrace();
114121
}
115122
}
116123

0 commit comments

Comments
 (0)