Skip to content

Commit ffe06dd

Browse files
committed
Remove deprecations from functional interfaces
1 parent 9b455b2 commit ffe06dd

File tree

8 files changed

+119
-138
lines changed

8 files changed

+119
-138
lines changed

log4j-api-test/src/test/java/org/apache/logging/log4j/internal/map/UnmodifiableArrayBackedMapTest.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
import static org.junit.jupiter.api.Assertions.fail;
2525

2626
import java.util.ArrayList;
27+
import java.util.Collection;
2728
import java.util.Collections;
2829
import java.util.HashMap;
2930
import java.util.HashSet;
3031
import java.util.LinkedHashMap;
3132
import java.util.LinkedHashSet;
3233
import java.util.Map;
3334
import java.util.Set;
35+
import org.apache.logging.log4j.util.ReadOnlyStringMap;
3436
import org.apache.logging.log4j.util.TriConsumer;
3537
import org.junit.jupiter.api.Test;
3638

@@ -238,32 +240,18 @@ public void testEqualsWhenOneValueDiffers() {
238240

239241
@Test
240242
public void testForEachBiConsumer_JavaUtil() {
241-
UnmodifiableArrayBackedMap map = UnmodifiableArrayBackedMap.EMPTY_MAP.copyAndPutAll(getTestParameters());
242-
Set<String> keys = new HashSet<>();
243-
java.util.function.BiConsumer<String, String> java_util_action =
244-
new java.util.function.BiConsumer<String, String>() {
245-
@Override
246-
public void accept(String key, String value) {
247-
keys.add(key);
248-
}
249-
};
250-
map.forEach(java_util_action);
243+
final Map<String, String> map = UnmodifiableArrayBackedMap.EMPTY_MAP.copyAndPutAll(getTestParameters());
244+
final Collection<String> keys = new HashSet<>();
245+
map.forEach((key, value) -> keys.add(key));
251246
assertEquals(map.keySet(), keys);
252247
}
253248

254249
@Test
255250
public void testForEachBiConsumer_Log4jUtil() {
256-
UnmodifiableArrayBackedMap map = UnmodifiableArrayBackedMap.EMPTY_MAP.copyAndPutAll(getTestParameters());
257-
Set<String> keys = new HashSet<>();
258-
org.apache.logging.log4j.util.BiConsumer<String, String> log4j_util_action =
259-
new org.apache.logging.log4j.util.BiConsumer<String, String>() {
260-
@Override
261-
public void accept(String key, String value) {
262-
keys.add(key);
263-
}
264-
};
265-
map.forEach(log4j_util_action);
266-
assertEquals(map.keySet(), keys);
251+
final ReadOnlyStringMap map = UnmodifiableArrayBackedMap.EMPTY_MAP.copyAndPutAll(getTestParameters());
252+
final Collection<String> keys = new HashSet<>();
253+
map.forEach((key, value) -> keys.add(key));
254+
assertEquals(map.toMap().keySet(), keys);
267255
}
268256

269257
@Test

log4j-api/src/main/java/org/apache/logging/log4j/LogBuilder.java

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public interface LogBuilder {
3232
* @param marker The Marker to log.
3333
* @return The LogBuilder.
3434
*/
35-
default LogBuilder withMarker(Marker marker) {
35+
default LogBuilder withMarker(final Marker marker) {
3636
return this;
3737
}
3838

@@ -41,7 +41,7 @@ default LogBuilder withMarker(Marker marker) {
4141
* @param throwable The Throwable to log.
4242
* @return the LogBuilder.
4343
*/
44-
default LogBuilder withThrowable(Throwable throwable) {
44+
default LogBuilder withThrowable(final Throwable throwable) {
4545
return this;
4646
}
4747

@@ -59,21 +59,21 @@ default LogBuilder withLocation() {
5959
* @param location The stack trace element to include in the log event.
6060
* @return The LogBuilder.
6161
*/
62-
default LogBuilder withLocation(StackTraceElement location) {
62+
default LogBuilder withLocation(final StackTraceElement location) {
6363
return this;
6464
}
6565

6666
/**
6767
* Causes all the data collected to be logged along with the message. Interface default method does nothing.
6868
* @param message The message to log.
6969
*/
70-
default void log(CharSequence message) {}
70+
default void log(final CharSequence message) {}
7171

7272
/**
7373
* Causes all the data collected to be logged along with the message. Interface default method does nothing.
7474
* @param message The message to log.
7575
*/
76-
default void log(String message) {}
76+
default void log(final String message) {}
7777

7878
/**
7979
* Logs a message with parameters. Interface default method does nothing.
@@ -83,29 +83,27 @@ default void log(String message) {}
8383
*
8484
* @see org.apache.logging.log4j.util.Unbox
8585
*/
86-
default void log(String message, Object... params) {}
86+
default void log(final String message, final Object... params) {}
8787

8888
/**
8989
* Causes all the data collected to be logged along with the message and parameters.
9090
* Interface default method does nothing.
9191
* @param message The message.
9292
* @param params Parameters to the message.
9393
*/
94-
@SuppressWarnings("deprecation")
95-
default void log(String message, Supplier<?>... params) {}
94+
default void log(final String message, final Supplier<?>... params) {}
9695

9796
/**
9897
* Causes all the data collected to be logged along with the message. Interface default method does nothing.
9998
* @param message The message to log.
10099
*/
101-
default void log(Message message) {}
100+
default void log(final Message message) {}
102101

103102
/**
104103
* Causes all the data collected to be logged along with the message. Interface default method does nothing.
105104
* @param messageSupplier The supplier of the message to log.
106105
*/
107-
@SuppressWarnings("deprecation")
108-
default void log(Supplier<Message> messageSupplier) {}
106+
default void log(final Supplier<Message> messageSupplier) {}
109107

110108
/**
111109
* Causes all the data collected to be logged along with the message.
@@ -114,7 +112,6 @@ default void log(Supplier<Message> messageSupplier) {}
114112
* @return the message logger or {@code null} if no logging occurred.
115113
* @since 2.20
116114
*/
117-
@SuppressWarnings("deprecation")
118115
default Message logAndGet(final Supplier<Message> messageSupplier) {
119116
return null;
120117
}
@@ -123,7 +120,7 @@ default Message logAndGet(final Supplier<Message> messageSupplier) {
123120
* Causes all the data collected to be logged along with the message. Interface default method does nothing.
124121
* @param message The message to log.
125122
*/
126-
default void log(Object message) {}
123+
default void log(final Object message) {}
127124

128125
/**
129126
* Logs a message with parameters. Interface default method does nothing.
@@ -133,7 +130,7 @@ default void log(Object message) {}
133130
*
134131
* @see org.apache.logging.log4j.util.Unbox
135132
*/
136-
default void log(String message, Object p0) {}
133+
default void log(final String message, final Object p0) {}
137134

138135
/**
139136
* Logs a message with parameters. Interface default method does nothing.
@@ -144,7 +141,7 @@ default void log(String message, Object p0) {}
144141
*
145142
* @see org.apache.logging.log4j.util.Unbox
146143
*/
147-
default void log(String message, Object p0, Object p1) {}
144+
default void log(final String message, final Object p0, final Object p1) {}
148145

149146
/**
150147
* Logs a message with parameters. Interface default method does nothing.
@@ -156,7 +153,7 @@ default void log(String message, Object p0, Object p1) {}
156153
*
157154
* @see org.apache.logging.log4j.util.Unbox
158155
*/
159-
default void log(String message, Object p0, Object p1, Object p2) {}
156+
default void log(final String message, final Object p0, final Object p1, final Object p2) {}
160157

161158
/**
162159
* Logs a message with parameters. Interface default method does nothing.
@@ -169,7 +166,7 @@ default void log(String message, Object p0, Object p1, Object p2) {}
169166
*
170167
* @see org.apache.logging.log4j.util.Unbox
171168
*/
172-
default void log(String message, Object p0, Object p1, Object p2, Object p3) {}
169+
default void log(final String message, final Object p0, final Object p1, final Object p2, final Object p3) {}
173170

174171
/**
175172
* Logs a message with parameters. Interface default method does nothing.
@@ -183,7 +180,13 @@ default void log(String message, Object p0, Object p1, Object p2, Object p3) {}
183180
*
184181
* @see org.apache.logging.log4j.util.Unbox
185182
*/
186-
default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4) {}
183+
default void log(
184+
final String message,
185+
final Object p0,
186+
final Object p1,
187+
final Object p2,
188+
final Object p3,
189+
final Object p4) {}
187190

188191
/**
189192
* Logs a message with parameters. Interface default method does nothing.
@@ -198,7 +201,14 @@ default void log(String message, Object p0, Object p1, Object p2, Object p3, Obj
198201
*
199202
* @see org.apache.logging.log4j.util.Unbox
200203
*/
201-
default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) {}
204+
default void log(
205+
final String message,
206+
final Object p0,
207+
final Object p1,
208+
final Object p2,
209+
final Object p3,
210+
final Object p4,
211+
final Object p5) {}
202212

203213
/**
204214
* Logs a message with parameters.
@@ -214,7 +224,15 @@ default void log(String message, Object p0, Object p1, Object p2, Object p3, Obj
214224
*
215225
* @see org.apache.logging.log4j.util.Unbox
216226
*/
217-
default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) {}
227+
default void log(
228+
final String message,
229+
final Object p0,
230+
final Object p1,
231+
final Object p2,
232+
final Object p3,
233+
final Object p4,
234+
final Object p5,
235+
final Object p6) {}
218236

219237
/**
220238
* Logs a message with parameters. Interface default method does nothing.
@@ -232,7 +250,15 @@ default void log(String message, Object p0, Object p1, Object p2, Object p3, Obj
232250
* @see org.apache.logging.log4j.util.Unbox
233251
*/
234252
default void log(
235-
String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) {}
253+
final String message,
254+
final Object p0,
255+
final Object p1,
256+
final Object p2,
257+
final Object p3,
258+
final Object p4,
259+
final Object p5,
260+
final Object p6,
261+
final Object p7) {}
236262

237263
/**
238264
* Logs a message with parameters. Interface default method does nothing.
@@ -251,16 +277,16 @@ default void log(
251277
* @see org.apache.logging.log4j.util.Unbox
252278
*/
253279
default void log(
254-
String message,
255-
Object p0,
256-
Object p1,
257-
Object p2,
258-
Object p3,
259-
Object p4,
260-
Object p5,
261-
Object p6,
262-
Object p7,
263-
Object p8) {}
280+
final String message,
281+
final Object p0,
282+
final Object p1,
283+
final Object p2,
284+
final Object p3,
285+
final Object p4,
286+
final Object p5,
287+
final Object p6,
288+
final Object p7,
289+
final Object p8) {}
264290

265291
/**
266292
* Logs a message with parameters. Interface default method does nothing.
@@ -280,17 +306,17 @@ default void log(
280306
* @see org.apache.logging.log4j.util.Unbox
281307
*/
282308
default void log(
283-
String message,
284-
Object p0,
285-
Object p1,
286-
Object p2,
287-
Object p3,
288-
Object p4,
289-
Object p5,
290-
Object p6,
291-
Object p7,
292-
Object p8,
293-
Object p9) {}
309+
final String message,
310+
final Object p0,
311+
final Object p1,
312+
final Object p2,
313+
final Object p3,
314+
final Object p4,
315+
final Object p5,
316+
final Object p6,
317+
final Object p7,
318+
final Object p8,
319+
final Object p9) {}
294320

295321
/**
296322
* Causes all the data collected to be logged. Default implementatoin does nothing.

log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
public class LogManager {
4242

4343
/**
44-
* Log4j property to set to the fully qualified class name of a custom implementation of
44+
* Log4j's property to set to the fully qualified class name of a custom implementation of
4545
* {@link LoggerContextFactory}.
4646
* @deprecated Replaced since 2.24.0 with {@value org.apache.logging.log4j.spi.Provider#PROVIDER_PROPERTY_NAME}.
4747
*/
4848
@Deprecated
4949
public static final String FACTORY_PROPERTY_NAME = "log4j2.loggerContextFactory";
5050

5151
/**
52-
* The name of the root Logger is {@value #ROOT_LOGGER_NAME}.
52+
* The name of the root Logger.
5353
*/
5454
public static final String ROOT_LOGGER_NAME = Strings.EMPTY;
5555

@@ -315,10 +315,10 @@ protected static LoggerContext getContext(
315315
/**
316316
* Shutdown using the LoggerContext appropriate for the caller of this method.
317317
* This is equivalent to calling {@code LogManager.shutdown(false)}.
318-
*
319-
* This call is synchronous and will block until shut down is complete.
320-
* This may include flushing pending log events over network connections.
321-
*
318+
* <p>
319+
* This call is synchronous and will block until shut down is complete. This may include flushing pending log
320+
* events over network connections.
321+
* </p>
322322
* @since 2.6
323323
*/
324324
public static void shutdown() {
@@ -328,9 +328,10 @@ public static void shutdown() {
328328
/**
329329
* Shutdown the logging system if the logging system supports it.
330330
* This is equivalent to calling {@code LogManager.shutdown(LogManager.getContext(currentContext))}.
331-
*
332-
* This call is synchronous and will block until shut down is complete.
333-
* This may include flushing pending log events over network connections.
331+
* <p>
332+
* This call is synchronous and will block until shut down is complete. This may include flushing pending log
333+
* events over network connections.
334+
* </p>
334335
*
335336
* @param currentContext if true a default LoggerContext (may not be the LoggerContext used to create a Logger
336337
* for the calling class) will be used.
@@ -347,9 +348,10 @@ public static void shutdown(final boolean currentContext) {
347348
/**
348349
* Shutdown the logging system if the logging system supports it.
349350
* This is equivalent to calling {@code LogManager.shutdown(LogManager.getContext(currentContext))}.
350-
*
351-
* This call is synchronous and will block until shut down is complete.
352-
* This may include flushing pending log events over network connections.
351+
* <p>
352+
* This call is synchronous and will block until shut down is complete. This may include flushing pending log
353+
* events over network connections.
354+
* </p>
353355
*
354356
* @param currentContext if true a default LoggerContext (may not be the LoggerContext used to create a Logger
355357
* for the calling class) will be used.
@@ -366,9 +368,10 @@ public static void shutdown(final boolean currentContext, final boolean allConte
366368

367369
/**
368370
* Shutdown the logging system if the logging system supports it.
369-
*
370-
* This call is synchronous and will block until shut down is complete.
371-
* This may include flushing pending log events over network connections.
371+
* <p>
372+
* This call is synchronous and will block until shut down is complete. This may include flushing pending log
373+
* events over network connections.
374+
* </p>
372375
*
373376
* @param context the LoggerContext.
374377
* @since 2.6
@@ -461,7 +464,7 @@ public static Logger getFormatterLogger(final Class<?> clazz) {
461464
* Short-hand for {@code getLogger(value, StringFormatterMessageFactory.INSTANCE)}
462465
* </p>
463466
*
464-
* @param value The value's whose class name should be used as the Logger name.
467+
* @param value The value whose class name should be used as the Logger name.
465468
* @return The Logger, created with a {@link StringFormatterMessageFactory}
466469
* @throws UnsupportedOperationException if {@code value} is {@code null} and the calling class cannot be
467470
* determined.

0 commit comments

Comments
 (0)