This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new 3f5da0a884 Fix concurrent date-time formatting issue in
`PatternLayout` (#1485)
3f5da0a884 is described below
commit 3f5da0a884a04dc9633e33e8a3250649af898927
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Wed May 24 16:33:51 2023 +0200
Fix concurrent date-time formatting issue in `PatternLayout` (#1485)
---
.../log4j/core/pattern/DatePatternConverter.java | 15 ++++++-------
...5_fix_DatePatternConverter_when_TL_disabled.xml | 26 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
index d4cd5a3095..00d1c21020 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
@@ -325,16 +325,15 @@ public final class DatePatternConverter extends
LogEventPatternConverter impleme
}
private void formatWithoutThreadLocals(final Instant instant, final
StringBuilder output) {
- CachedTime cached = cachedTime.get();
+ final CachedTime effective;
+ final CachedTime cached = cachedTime.get();
if (instant.getEpochSecond() != cached.epochSecond ||
instant.getNanoOfSecond() != cached.nanoOfSecond) {
- final CachedTime newTime = new CachedTime(instant);
- if (cachedTime.compareAndSet(cached, newTime)) {
- cached = newTime;
- } else {
- cached = cachedTime.get();
- }
+ effective = new CachedTime(instant);
+ cachedTime.compareAndSet(cached, effective);
+ } else {
+ effective = cached;
}
- output.append(cached.formatted);
+ output.append(effective.formatted);
}
/**
diff --git
a/src/changelog/.2.x.x/1485_fix_DatePatternConverter_when_TL_disabled.xml
b/src/changelog/.2.x.x/1485_fix_DatePatternConverter_when_TL_disabled.xml
new file mode 100644
index 0000000000..86886dd651
--- /dev/null
+++ b/src/changelog/.2.x.x/1485_fix_DatePatternConverter_when_TL_disabled.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to you under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://logging.apache.org/log4j/changelog"
+ xsi:schemaLocation="http://logging.apache.org/log4j/changelog
https://logging.apache.org/log4j/changelog-0.1.1.xsd"
+ type="fixed">
+ <issue id="1485"
link="https://github.com/apache/logging-log4j2/issues/1485"/>
+ <author name="Stephan Markwalder" id="smarkwal"/>
+ <author id="vy"/>
+ <description format="asciidoc">Fix concurrent date-time formatting issue in
`PatternLayout`</description>
+</entry>