You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2023/05/23 20:19:12 UTC
[logging-log4j2] 01/01: Fix concurrent date-time formatting issue in `PatternLayout`
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch DatePatternConverter-non-TL-fix
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit fb9f2ebbcc5b2e33ce6bf073d3d92cd1cdacf340
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue May 23 22:19:09 2023 +0200
Fix concurrent date-time formatting issue in `PatternLayout`
---
.../log4j/core/pattern/DatePatternConverter.java | 15 ++++++-------
...0_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/0_fix_DatePatternConverter_when_TL_disabled.xml b/src/changelog/.2.x.x/0_fix_DatePatternConverter_when_TL_disabled.xml
new file mode 100644
index 0000000000..b1f4ab8de1
--- /dev/null
+++ b/src/changelog/.2.x.x/0_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="0" link="https://github.com/apache/logging-log4j2/issues/0"/>
+ <author name="Stephan Markwalder" id="smarkwal"/>
+ <author id="vy"/>
+ <description format="asciidoc">Fix concurrent date-time formatting issue in `PatternLayout`</description>
+</entry>