Skip to content

Commit ad1a505

Browse files
committed
Restore code to 2.24.1
1 parent 2a9a380 commit ad1a505

File tree

35 files changed

+259
-349
lines changed

35 files changed

+259
-349
lines changed

log4j-api/src/main/java/org/apache/logging/log4j/message/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Public Message Types used for Log4j 2. Users may implement their own Messages.
2020
*/
2121
@Export
22-
@Version("2.24.2")
22+
@Version("2.24.1")
2323
package org.apache.logging.log4j.message;
2424

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

log4j-api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ public ExtendedLogger getLogger(final String name) {
102102
public ExtendedLogger getLogger(final String name, @Nullable final MessageFactory messageFactory) {
103103
final MessageFactory effectiveMessageFactory =
104104
messageFactory != null ? messageFactory : DEFAULT_MESSAGE_FACTORY;
105-
return loggerRegistry.computeIfAbsent(name, effectiveMessageFactory, this::createLogger);
105+
final ExtendedLogger oldLogger = loggerRegistry.getLogger(name, effectiveMessageFactory);
106+
if (oldLogger != null) {
107+
return oldLogger;
108+
}
109+
final ExtendedLogger newLogger = createLogger(name, effectiveMessageFactory);
110+
loggerRegistry.putIfAbsent(name, effectiveMessageFactory, newLogger);
111+
return loggerRegistry.getLogger(name, effectiveMessageFactory);
106112
}
107113

108114
private ExtendedLogger createLogger(final String name, @Nullable final MessageFactory messageFactory) {

log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,7 @@ private static MessageFactory2 adaptMessageFactory(final MessageFactory result)
166166
*
167167
* @param logger The logger to check
168168
* @param messageFactory The message factory to check.
169-
* @deprecated As of version {@code 2.25.0}, planned to be removed!
170-
* Instead, in {@link LoggerContext#getLogger(String, MessageFactory)} implementations, namespace loggers with message factories.
171-
* If your implementation uses {@link LoggerRegistry}, you are already covered.
172169
*/
173-
@Deprecated
174170
public static void checkMessageFactory(final ExtendedLogger logger, final MessageFactory messageFactory) {
175171
final String name = logger.getName();
176172
final MessageFactory loggerMessageFactory = logger.getMessageFactory();

log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java

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

1919
import org.apache.logging.log4j.Logger;
2020
import org.apache.logging.log4j.message.MessageFactory;
21-
import org.jspecify.annotations.Nullable;
2221

2322
/**
2423
* Anchor point for logging implementations.
@@ -55,7 +54,7 @@ default ExtendedLogger getLogger(Class<?> cls) {
5554
* @return The logger.
5655
* @since 2.14.0
5756
*/
58-
default ExtendedLogger getLogger(Class<?> cls, @Nullable MessageFactory messageFactory) {
57+
default ExtendedLogger getLogger(Class<?> cls, MessageFactory messageFactory) {
5958
final String canonicalName = cls.getCanonicalName();
6059
return getLogger(canonicalName != null ? canonicalName : cls.getName(), messageFactory);
6160
}
@@ -74,7 +73,7 @@ default ExtendedLogger getLogger(Class<?> cls, @Nullable MessageFactory messageF
7473
* the logger but will log a warning if mismatched.
7574
* @return The logger with the specified name.
7675
*/
77-
ExtendedLogger getLogger(String name, @Nullable MessageFactory messageFactory);
76+
ExtendedLogger getLogger(String name, MessageFactory messageFactory);
7877

7978
/**
8079
* Gets the LoggerRegistry.
@@ -119,7 +118,7 @@ default Object getObject(String key) {
119118
* @return true if the Logger exists, false otherwise.
120119
* @since 2.5
121120
*/
122-
boolean hasLogger(String name, @Nullable MessageFactory messageFactory);
121+
boolean hasLogger(String name, MessageFactory messageFactory);
123122

124123
/**
125124
* Associates an object into the LoggerContext by name for later use.

log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerRegistry.java

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,12 @@
3030
import java.util.concurrent.locks.Lock;
3131
import java.util.concurrent.locks.ReadWriteLock;
3232
import java.util.concurrent.locks.ReentrantReadWriteLock;
33-
import java.util.function.BiFunction;
3433
import org.apache.logging.log4j.message.MessageFactory;
3534
import org.apache.logging.log4j.message.ParameterizedMessageFactory;
36-
import org.apache.logging.log4j.status.StatusLogger;
37-
import org.jspecify.annotations.NullMarked;
38-
import org.jspecify.annotations.Nullable;
3935

4036
/**
4137
* Convenience class to be used as an {@link ExtendedLogger} registry by {@code LoggerContext} implementations.
4238
*/
43-
@NullMarked
4439
public class LoggerRegistry<T extends ExtendedLogger> {
4540

4641
private final Map<String, Map<MessageFactory, WeakReference<T>>> loggerRefByMessageFactoryByName = new HashMap<>();
@@ -55,9 +50,7 @@ public class LoggerRegistry<T extends ExtendedLogger> {
5550
* Data structure contract for the internal storage of admitted loggers.
5651
*
5752
* @param <T> subtype of {@code ExtendedLogger}
58-
* @deprecated As of version {@code 2.25.0}, planned to be removed!
5953
*/
60-
@Deprecated
6154
public interface MapFactory<T extends ExtendedLogger> {
6255

6356
Map<String, T> createInnerMap();
@@ -71,9 +64,7 @@ public interface MapFactory<T extends ExtendedLogger> {
7164
* {@link MapFactory} implementation using {@link ConcurrentHashMap}.
7265
*
7366
* @param <T> subtype of {@code ExtendedLogger}
74-
* @deprecated As of version {@code 2.25.0}, planned to be removed!
7567
*/
76-
@Deprecated
7768
public static class ConcurrentMapFactory<T extends ExtendedLogger> implements MapFactory<T> {
7869

7970
@Override
@@ -96,9 +87,7 @@ public void putIfAbsent(final Map<String, T> innerMap, final String name, final
9687
* {@link MapFactory} implementation using {@link WeakHashMap}.
9788
*
9889
* @param <T> subtype of {@code ExtendedLogger}
99-
* @deprecated As of version {@code 2.25.0}, planned to be removed!
10090
*/
101-
@Deprecated
10291
public static class WeakMapFactory<T extends ExtendedLogger> implements MapFactory<T> {
10392

10493
@Override
@@ -123,10 +112,8 @@ public LoggerRegistry() {}
123112
* Constructs an instance <b>ignoring</b> the given the map factory.
124113
*
125114
* @param mapFactory a map factory
126-
* @deprecated As of version {@code 2.25.0}, planned to be removed!
127115
*/
128-
@Deprecated
129-
public LoggerRegistry(@Nullable final MapFactory<T> mapFactory) {
116+
public LoggerRegistry(final MapFactory<T> mapFactory) {
130117
this();
131118
}
132119

@@ -139,10 +126,7 @@ public LoggerRegistry(@Nullable final MapFactory<T> mapFactory) {
139126
*
140127
* @param name a logger name
141128
* @return the logger associated with the name
142-
* @deprecated As of version {@code 2.25.0}, planned to be removed!
143-
* Use {@link #getLogger(String, MessageFactory)} instead.
144129
*/
145-
@Deprecated
146130
public T getLogger(final String name) {
147131
requireNonNull(name, "name");
148132
return getLogger(name, null);
@@ -160,7 +144,7 @@ public T getLogger(final String name) {
160144
* @param messageFactory a message factory
161145
* @return the logger associated with the given name and message factory
162146
*/
163-
public T getLogger(final String name, @Nullable final MessageFactory messageFactory) {
147+
public T getLogger(final String name, final MessageFactory messageFactory) {
164148
requireNonNull(name, "name");
165149
readLock.lock();
166150
try {
@@ -209,10 +193,7 @@ public Collection<T> getLoggers(final Collection<T> destination) {
209193
*
210194
* @param name a logger name
211195
* @return {@code true}, if the logger exists; {@code false} otherwise.
212-
* @deprecated As of version {@code 2.25.0}, planned to be removed!
213-
* Use {@link #hasLogger(String, MessageFactory)} instead.
214196
*/
215-
@Deprecated
216197
public boolean hasLogger(final String name) {
217198
requireNonNull(name, "name");
218199
final T logger = getLogger(name);
@@ -232,7 +213,7 @@ public boolean hasLogger(final String name) {
232213
* @return {@code true}, if the logger exists; {@code false} otherwise.
233214
* @since 2.5
234215
*/
235-
public boolean hasLogger(final String name, @Nullable final MessageFactory messageFactory) {
216+
public boolean hasLogger(final String name, final MessageFactory messageFactory) {
236217
requireNonNull(name, "name");
237218
final T logger = getLogger(name, messageFactory);
238219
return logger != null;
@@ -265,23 +246,18 @@ public boolean hasLogger(final String name, final Class<? extends MessageFactory
265246
* @param name ignored – kept for backward compatibility
266247
* @param messageFactory ignored – kept for backward compatibility
267248
* @param logger a logger instance
268-
* @deprecated As of version {@code 2.25.0}, planned to be removed!
269-
* Use {@link #computeIfAbsent(String, MessageFactory, BiFunction)} instead.
270249
*/
271-
@Deprecated
272-
public void putIfAbsent(
273-
@Nullable final String name, @Nullable final MessageFactory messageFactory, final T logger) {
250+
public void putIfAbsent(final String name, final MessageFactory messageFactory, final T logger) {
274251

275252
// Check arguments
276253
requireNonNull(logger, "logger");
277254

278255
// Insert the logger
279256
writeLock.lock();
280257
try {
281-
final String loggerName = logger.getName();
282258
final Map<MessageFactory, WeakReference<T>> loggerRefByMessageFactory =
283259
loggerRefByMessageFactoryByName.computeIfAbsent(
284-
loggerName, this::createLoggerRefByMessageFactoryMap);
260+
logger.getName(), this::createLoggerRefByMessageFactoryMap);
285261
final MessageFactory loggerMessageFactory = logger.getMessageFactory();
286262
final WeakReference<T> loggerRef = loggerRefByMessageFactory.get(loggerMessageFactory);
287263
if (loggerRef == null || loggerRef.get() == null) {
@@ -292,60 +268,6 @@ public void putIfAbsent(
292268
}
293269
}
294270

295-
public T computeIfAbsent(
296-
final String name,
297-
final MessageFactory messageFactory,
298-
final BiFunction<String, MessageFactory, T> loggerSupplier) {
299-
300-
// Check arguments
301-
requireNonNull(name, "name");
302-
requireNonNull(messageFactory, "messageFactory");
303-
requireNonNull(loggerSupplier, "loggerSupplier");
304-
305-
// Read lock fast path: See if logger already exists
306-
T logger = getLogger(name, messageFactory);
307-
if (logger != null) {
308-
return logger;
309-
}
310-
311-
// Write lock slow path: Insert the logger
312-
writeLock.lock();
313-
try {
314-
315-
// See if the logger is created by another thread in the meantime
316-
final Map<MessageFactory, WeakReference<T>> loggerRefByMessageFactory =
317-
loggerRefByMessageFactoryByName.computeIfAbsent(name, this::createLoggerRefByMessageFactoryMap);
318-
final WeakReference<T> loggerRef;
319-
if ((loggerRef = loggerRefByMessageFactory.get(messageFactory)) != null
320-
&& (logger = loggerRef.get()) != null) {
321-
return logger;
322-
}
323-
324-
// Create the logger
325-
logger = loggerSupplier.apply(name, messageFactory);
326-
327-
// Report message factory mismatches, if there is any
328-
final MessageFactory loggerMessageFactory = logger.getMessageFactory();
329-
if (!loggerMessageFactory.equals(messageFactory)) {
330-
StatusLogger.getLogger()
331-
.error(
332-
"Newly registered logger with name `{}` and message factory `{}`, is requested to be associated with a different message factory: `{}`.\n"
333-
+ "Effectively the message factory of the logger will be used and the other one will be ignored.\n"
334-
+ "This generally hints a problem at the logger context implementation.\n"
335-
+ "Please report this using the Log4j project issue tracker.",
336-
name,
337-
loggerMessageFactory,
338-
messageFactory);
339-
}
340-
341-
// Insert the logger
342-
loggerRefByMessageFactory.put(loggerMessageFactory, new WeakReference<>(logger));
343-
return logger;
344-
} finally {
345-
writeLock.unlock();
346-
}
347-
}
348-
349271
private Map<MessageFactory, WeakReference<T>> createLoggerRefByMessageFactoryMap(final String ignored) {
350272
return new WeakHashMap<>();
351273
}

log4j-api/src/main/java/org/apache/logging/log4j/spi/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* API classes.
2020
*/
2121
@Export
22-
@Version("2.25.0")
22+
@Version("2.24.1")
2323
package org.apache.logging.log4j.spi;
2424

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

log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.apache.logging.log4j.spi.Terminable;
5656
import org.apache.logging.log4j.spi.ThreadContextMapFactory;
5757
import org.apache.logging.log4j.util.PropertiesUtil;
58-
import org.jspecify.annotations.Nullable;
5958

6059
/**
6160
* The LoggerContext is the anchor for the logging system. It maintains a list of all the loggers requested by
@@ -524,10 +523,16 @@ public Collection<Logger> getLoggers() {
524523
* @return a logger matching the given name and message factory
525524
*/
526525
@Override
527-
public Logger getLogger(final String name, @Nullable final MessageFactory messageFactory) {
526+
public Logger getLogger(final String name, final MessageFactory messageFactory) {
528527
final MessageFactory effectiveMessageFactory =
529528
messageFactory != null ? messageFactory : DEFAULT_MESSAGE_FACTORY;
530-
return loggerRegistry.computeIfAbsent(name, effectiveMessageFactory, this::newInstance);
529+
final Logger oldLogger = loggerRegistry.getLogger(name, effectiveMessageFactory);
530+
if (oldLogger != null) {
531+
return oldLogger;
532+
}
533+
final Logger newLogger = newInstance(name, effectiveMessageFactory);
534+
loggerRegistry.putIfAbsent(name, effectiveMessageFactory, newLogger);
535+
return loggerRegistry.getLogger(name, effectiveMessageFactory);
531536
}
532537

533538
/**
@@ -558,7 +563,7 @@ public boolean hasLogger(final String name) {
558563
* @return True if the Logger exists, false otherwise.
559564
*/
560565
@Override
561-
public boolean hasLogger(final String name, @Nullable final MessageFactory messageFactory) {
566+
public boolean hasLogger(final String name, final MessageFactory messageFactory) {
562567
final MessageFactory effectiveMessageFactory =
563568
messageFactory != null ? messageFactory : DEFAULT_MESSAGE_FACTORY;
564569
return loggerRegistry.hasLogger(name, effectiveMessageFactory);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static int parseInt(final String s, final int defaultValue) {
172172
private final boolean ignoreExceptions;
173173
private final Layout<? extends Serializable> layout;
174174

175-
private volatile ErrorHandler handler = new DefaultErrorHandler(this);
175+
private ErrorHandler handler = new DefaultErrorHandler(this);
176176

177177
@Override
178178
public boolean requiresLocation() {
@@ -316,6 +316,10 @@ public void setHandler(final ErrorHandler handler) {
316316
LOGGER.error("The handler cannot be set to null");
317317
return;
318318
}
319+
if (isStarted()) {
320+
LOGGER.error("The handler cannot be changed once the appender is started");
321+
return;
322+
}
319323
this.handler = handler;
320324
}
321325

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ public void send(final Layout<?> layout, final LogEvent event) throws IOExceptio
100100
header.getName(), header.evaluate(getConfiguration().getStrSubstitutor()));
101101
}
102102
if (sslConfiguration != null) {
103-
((HttpsURLConnection) urlConnection)
104-
.setSSLSocketFactory(sslConfiguration.getSslContext().getSocketFactory());
103+
((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
105104
}
106105
if (isHttps && !verifyHostname) {
107106
((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Provides Asynchronous Logger classes and interfaces for low-latency logging.
1919
*/
2020
@Export
21-
@Version("2.24.1")
21+
@Version("2.24.0")
2222
package org.apache.logging.log4j.core.async;
2323

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

0 commit comments

Comments
 (0)