This is an automated email from the ASF dual-hosted git repository.

freeandnil pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git


The following commit(s) were added to refs/heads/master by this push:
     new 50738b0b #246 fix InvalidCastException in 
ThreadContextStack.InternalStack.set (fixes #245) (#246)
50738b0b is described below

commit 50738b0b229cf890a5f4c86aa244be24e95e5779
Author: Jan Friedrich <[email protected]>
AuthorDate: Thu May 22 11:08:07 2025 +0200

    #246 fix InvalidCastException in ThreadContextStack.InternalStack.set 
(fixes #245) (#246)
---
 src/changelog/3.1.1/.release-notes.adoc.ftl | 41 ++++++++++++++++++++
 src/changelog/3.1.1/.release.xml            |  6 +++
 src/changelog/3.1.1/245-ndc-inherit.xml     | 12 ++++++
 src/log4net.Tests/NdcTest.cs                | 58 +++++++++++++++++++++++++++++
 src/log4net.sln                             |  4 --
 src/log4net/Util/ThreadContextStack.cs      |  4 +-
 6 files changed, 119 insertions(+), 6 deletions(-)

diff --git a/src/changelog/3.1.1/.release-notes.adoc.ftl 
b/src/changelog/3.1.1/.release-notes.adoc.ftl
new file mode 100644
index 00000000..85eb1e0e
--- /dev/null
+++ b/src/changelog/3.1.1/.release-notes.adoc.ftl
@@ -0,0 +1,41 @@
+////
+    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.
+////
+
+////
+    ██     ██  █████  ██████  ███    ██ ██ ███    ██  ██████  ██
+    ██     ██ ██   ██ ██   ██ ████   ██ ██ ████   ██ ██       ██
+    ██  █  ██ ███████ ██████  ██ ██  ██ ██ ██ ██  ██ ██   ███ ██
+    ██ ███ ██ ██   ██ ██   ██ ██  ██ ██ ██ ██  ██ ██ ██    ██
+     ███ ███  ██   ██ ██   ██ ██   ████ ██ ██   ████  ██████  ██
+
+    IF THIS FILE DOESN'T HAVE A `.ftl` SUFFIX, IT IS AUTO-GENERATED, DO NOT 
EDIT IT!
+
+    Version-specific release notes (`7.8.0.adoc`, etc.) are generated from 
`src/changelog/*/.release-notes.adoc.ftl`.
+    Auto-generation happens during `generate-sources` phase of Maven.
+    Hence, you must always
+
+    1. Find and edit the associated `.release-notes.adoc.ftl`
+    2. Run `./mvnw generate-sources`
+    3. Commit both `.release-notes.adoc.ftl` and the generated `7.8.0.adoc`
+////
+
+[#release-notes-${release.version?replace("[^a-zA-Z0-9]", "-", "r")}]
+== ${release.version}
+
+<#if release.date?has_content>Release date:: ${release.date}</#if>
+
+<#include "../.changelog.adoc.ftl">
diff --git a/src/changelog/3.1.1/.release.xml b/src/changelog/3.1.1/.release.xml
new file mode 100644
index 00000000..fa4c2ba8
--- /dev/null
+++ b/src/changelog/3.1.1/.release.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<release xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xmlns="https://logging.apache.org/xml/ns";
+         xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+         date="2025-07-12"
+         version="3.1.1"/>
diff --git a/src/changelog/3.1.1/245-ndc-inherit.xml 
b/src/changelog/3.1.1/245-ndc-inherit.xml
new file mode 100644
index 00000000..79faf00d
--- /dev/null
+++ b/src/changelog/3.1.1/245-ndc-inherit.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="https://logging.apache.org/xml/ns";
+       xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="fixed">
+  <issue id="245" link="https://github.com/apache/logging-log4net/issues/245"/>
+  <issue id="246" link="https://github.com/apache/logging-log4net/pull/246"/>
+  <description format="asciidoc">
+    Fix InvalidCastException in NDC.Inherit(System.Collections.Stack)
+    (reported by @jberg7, implemented by @freeandnil in 
https://github.com/apache/logging-log4net/pull/246[#246])
+  </description>
+</entry>
\ No newline at end of file
diff --git a/src/log4net.Tests/NdcTest.cs b/src/log4net.Tests/NdcTest.cs
new file mode 100644
index 00000000..ee5b14d3
--- /dev/null
+++ b/src/log4net.Tests/NdcTest.cs
@@ -0,0 +1,58 @@
+#region Apache License
+//
+// 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.
+//
+#endregion
+
+using System;
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using log4net.Config;
+using log4net.Core;
+using log4net.Layout;
+using log4net.Layout.Pattern;
+using log4net.Repository;
+using log4net.Tests.Appender;
+using log4net.Util;
+using NUnit.Framework;
+
+namespace log4net.Tests;
+
+/// <summary>
+/// Used for internal unit testing the <see cref="NDC"/> class.
+/// </summary>
+[TestFixture]
+public class NdcTest
+{
+  /// <summary>
+  /// Test regression (https://github.com/apache/logging-log4net/issues/245)
+  /// </summary>
+  [Test]
+  public void InheritTest()
+  {
+    NDC.Push("first");
+    NDC.Push("last");
+    System.Collections.Stack context = NDC.CloneStack();
+    NDC.Clear();
+    NDC.Inherit(context);
+    Assert.That(NDC.Pop(), Is.EqualTo("last"));
+    Assert.That(NDC.Pop(), Is.EqualTo("first"));
+  }
+}
\ No newline at end of file
diff --git a/src/log4net.sln b/src/log4net.sln
index 88013e13..3ecbc281 100644
--- a/src/log4net.sln
+++ b/src/log4net.sln
@@ -41,13 +41,9 @@ EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".doc", ".doc", 
"{33D80AD3-8048-4220-8BB0-38E3BDE5FCF4}"
        ProjectSection(SolutionItems) = preProject
                ..\doc\BUILDING.md = ..\doc\BUILDING.md
-               site\xdoc\release\config-examples.xml = 
site\xdoc\release\config-examples.xml
-               site\xdoc\download_log4net.xml = site\xdoc\download_log4net.xml
                ..\doc\MailTemplate.Announce.txt = 
..\doc\MailTemplate.Announce.txt
                ..\doc\MailTemplate.Result.txt = ..\doc\MailTemplate.Result.txt
                ..\doc\MailTemplate.txt = ..\doc\MailTemplate.txt
-               site\xdoc\release\release-notes.xml = 
site\xdoc\release\release-notes.xml
-               site\xdoc\release\release-review-instructions.xml = 
site\xdoc\release\release-review-instructions.xml
                ..\doc\RELEASING.md = ..\doc\RELEASING.md
        EndProjectSection
 EndProject
diff --git a/src/log4net/Util/ThreadContextStack.cs 
b/src/log4net/Util/ThreadContextStack.cs
index bb13aa04..23a31feb 100644
--- a/src/log4net/Util/ThreadContextStack.cs
+++ b/src/log4net/Util/ThreadContextStack.cs
@@ -188,10 +188,10 @@ internal Stack InternalStack
     set
     {
       _stack.Clear();
-      var frames = (StackFrame[])value.ToArray();
+      object[] frames = value.ToArray();
       for (int i = frames.Length - 1; i >= 0; i--)
       {
-        _stack.Push(frames[i]);
+        _stack.Push(frames[i].EnsureIs<StackFrame>());
       }
     }
   }

Reply via email to