Skip to content

Commit 3c5949b

Browse files
committed
Fix SEI MET07-J violations
This change: - Deprecates public/protected hiding methods. - Removes package-private hiding methods. - For legacy modules that will disappear in 3.x, just suppresses the warning. Closes #3601
1 parent 86781fd commit 3c5949b

File tree

15 files changed

+61
-22
lines changed

15 files changed

+61
-22
lines changed

log4j-1.2-api/src/main/java/org/apache/log4j/Hierarchy.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.log4j;
1818

19+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1920
import java.util.Enumeration;
2021
import java.util.Hashtable;
2122
import java.util.Vector;
@@ -79,10 +80,16 @@ protected Logger newLogger(final String name, final org.apache.logging.log4j.spi
7980
private static class PrivateLogManager extends org.apache.logging.log4j.LogManager {
8081
private static final String FQCN = Hierarchy.class.getName();
8182

83+
@SuppressFBWarnings(
84+
value = "HSM_HIDING_METHOD",
85+
justification = "The class is private, no confusion can arise.")
8286
public static LoggerContext getContext() {
8387
return getContext(FQCN, false);
8488
}
8589

90+
@SuppressFBWarnings(
91+
value = "HSM_HIDING_METHOD",
92+
justification = "The class is private, no confusion can arise.")
8693
public static org.apache.logging.log4j.Logger getLogger(final String name) {
8794
return getLogger(FQCN, name);
8895
}

log4j-1.2-api/src/main/java/org/apache/log4j/bridge/LogEventAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
public class LogEventAdapter extends LoggingEvent {
3939

40-
private static final long JVM_START_TIME = initStartTime();
40+
public static final long JVM_START_TIME = initStartTime();
4141

4242
private final LogEvent event;
4343

@@ -50,7 +50,7 @@ public LogEventAdapter(final LogEvent event) {
5050
* elapsed since 01.01.1970.
5151
* @return the time when the JVM started.
5252
*/
53-
public static long getStartTime() {
53+
public static long getJvmStartTime() {
5454
return JVM_START_TIME;
5555
}
5656

log4j-1.2-api/src/main/java/org/apache/log4j/helpers/UtilLoggingLevel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.apache.logging.log4j.util.Strings.toRootUpperCase;
2020

21+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2122
import java.util.ArrayList;
2223
import java.util.List;
2324
import org.apache.log4j.Level;
@@ -157,6 +158,7 @@ public static UtilLoggingLevel toLevel(final int val, final UtilLoggingLevel def
157158
* @param val numeric value.
158159
* @return matching level or UtilLoggerLevel.FINEST if no match.
159160
*/
161+
@SuppressFBWarnings(value = "HSM_HIDING_METHOD", justification = "Legacy code")
160162
public static Level toLevel(final int val) {
161163
return toLevel(val, FINEST);
162164
}
@@ -184,6 +186,7 @@ public static List getAllPossibleLevels() {
184186
* @param s symbolic name.
185187
* @return matching level or Level.DEBUG if no match.
186188
*/
189+
@SuppressFBWarnings(value = "HSM_HIDING_METHOD", justification = "Legacy code")
187190
public static Level toLevel(final String s) {
188191
return toLevel(s, Level.DEBUG);
189192
}
@@ -195,6 +198,7 @@ public static Level toLevel(final String s) {
195198
* @param defaultLevel level to return if no match.
196199
* @return matching level or defaultLevel if no match.
197200
*/
201+
@SuppressFBWarnings(value = "HSM_HIDING_METHOD", justification = "Legacy code")
198202
public static Level toLevel(final String sArg, final Level defaultLevel) {
199203
if (sArg == null) {
200204
return defaultLevel;

log4j-1.2-api/src/main/java/org/apache/log4j/helpers/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Log4j 1.x compatibility layer.
1919
*/
2020
@Export
21-
@Version("2.20.2")
21+
@Version("2.20.3")
2222
package org.apache.log4j.helpers;
2323

2424
import org.osgi.annotation.bundle.Export;

log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggingEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class LoggingEvent {
3535
* @return the JVM start time.
3636
*/
3737
public static long getStartTime() {
38-
return LogEventAdapter.getStartTime();
38+
return LogEventAdapter.getJvmStartTime();
3939
}
4040

4141
/**

log4j-appserver/src/main/java/org/apache/logging/log4j/appserver/jetty/Log4j2Logger.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.appserver.jetty;
1818

19+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1920
import org.apache.logging.log4j.Level;
2021
import org.apache.logging.log4j.LogManager;
2122
import org.apache.logging.log4j.spi.ExtendedLogger;
@@ -51,6 +52,7 @@ public class Log4j2Logger extends AbstractLogger {
5152
*/
5253
private static class PrivateManager extends LogManager {
5354

55+
@SuppressFBWarnings("HSM_HIDING_METHOD")
5456
public static LoggerContext getContext() {
5557
final ClassLoader cl = AbstractLogger.class.getClassLoader();
5658
return getContext(PARENT_FQCN, cl, false);

log4j-appserver/src/main/java/org/apache/logging/log4j/appserver/tomcat/TomcatLogger.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import aQute.bnd.annotation.Resolution;
2020
import aQute.bnd.annotation.spi.ServiceProvider;
21+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2122
import java.net.URI;
2223
import java.net.URISyntaxException;
2324
import java.net.URL;
@@ -163,6 +164,7 @@ public void fatal(final Object o, final Throwable throwable) {
163164
*/
164165
private static class PrivateManager extends LogManager {
165166

167+
@SuppressFBWarnings("HSM_HIDING_METHOD")
166168
public static LoggerContext getContext() {
167169
final ClassLoader cl = TomcatLogger.class.getClassLoader();
168170
URI uri = null;

log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.core.async;
1818

19+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1920
import java.util.Arrays;
2021
import java.util.List;
2122
import java.util.concurrent.TimeUnit;
@@ -90,7 +91,7 @@ public LoggerConfig build() {
9091
isAdditivity(),
9192
getProperties(),
9293
getConfig(),
93-
includeLocation(getIncludeLocation()));
94+
shouldIncludeLocation(getIncludeLocation()));
9495
}
9596
}
9697

@@ -272,7 +273,14 @@ public static LoggerConfig createLogger(
272273
final boolean additive = Booleans.parseBoolean(additivity, true);
273274

274275
return new AsyncLoggerConfig(
275-
name, appenderRefs, filter, level, additive, properties, config, includeLocation(includeLocation));
276+
name,
277+
appenderRefs,
278+
filter,
279+
level,
280+
additive,
281+
properties,
282+
config,
283+
shouldIncludeLocation(includeLocation));
276284
}
277285

278286
/**
@@ -290,6 +298,7 @@ public static LoggerConfig createLogger(
290298
* @since 3.0
291299
*/
292300
@Deprecated
301+
@SuppressFBWarnings("HSM_HIDING_METHOD")
293302
public static LoggerConfig createLogger(
294303
@PluginAttribute(value = "additivity", defaultBoolean = true) final boolean additivity,
295304
@PluginAttribute("level") final Level level,
@@ -309,11 +318,20 @@ public static LoggerConfig createLogger(
309318
additivity,
310319
properties,
311320
config,
312-
includeLocation(includeLocation));
321+
shouldIncludeLocation(includeLocation));
313322
}
314323

315-
// Note: for asynchronous loggers, includeLocation default is FALSE
324+
/**
325+
* @deprecated since 2.25.0. The method will become private in version 3.0.
326+
*/
327+
@Deprecated
328+
@SuppressFBWarnings(value = "HSM_HIDING_METHOD", justification = "Should be private.")
316329
protected static boolean includeLocation(final String includeLocationConfigValue) {
330+
return shouldIncludeLocation(includeLocationConfigValue);
331+
}
332+
333+
// Note: for asynchronous loggers, includeLocation default is FALSE
334+
private static boolean shouldIncludeLocation(final String includeLocationConfigValue) {
317335
return Boolean.parseBoolean(includeLocationConfigValue);
318336
}
319337

@@ -342,7 +360,7 @@ public LoggerConfig build() {
342360
isAdditivity(),
343361
getProperties(),
344362
getConfig(),
345-
AsyncLoggerConfig.includeLocation(getIncludeLocation()));
363+
shouldIncludeLocation(getIncludeLocation()));
346364
}
347365
}
348366

@@ -375,7 +393,7 @@ public static LoggerConfig createLogger(
375393
additive,
376394
properties,
377395
config,
378-
AsyncLoggerConfig.includeLocation(includeLocation));
396+
shouldIncludeLocation(includeLocation));
379397
}
380398

381399
/**
@@ -401,7 +419,7 @@ public static LoggerConfig createLogger(
401419
additive,
402420
properties,
403421
config,
404-
AsyncLoggerConfig.includeLocation(includeLocation));
422+
shouldIncludeLocation(includeLocation));
405423
}
406424
}
407425
}

log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MainMapLookup.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.core.lookup;
1818

19+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1920
import java.util.Map;
2021
import org.apache.logging.log4j.core.LogEvent;
2122
import org.apache.logging.log4j.core.config.plugins.Plugin;
@@ -74,6 +75,9 @@ public MainMapLookup(final Map<String, String> map) {
7475
* @param args
7576
* An application's {@code public static main(String[])} arguments.
7677
*/
78+
@SuppressFBWarnings(
79+
value = "HSM_HIDING_METHOD",
80+
justification = "The MapLookup.setMainArguments() method hidden by this one is deprecated.")
7781
public static void setMainArguments(final String... args) {
7882
if (args == null) {
7983
return;

log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* {@link org.apache.logging.log4j.core.lookup.StrLookup#CATEGORY Lookup}.
2222
*/
2323
@Export
24-
@Version("2.24.0")
24+
@Version("2.24.1")
2525
package org.apache.logging.log4j.core.lookup;
2626

2727
import org.osgi.annotation.bundle.Export;

0 commit comments

Comments
 (0)