You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2023/01/30 19:54:31 UTC

[logging-log4j2] branch master updated (3134b2d5db -> 2ae69a935f)

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

pkarwasz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


    from 3134b2d5db Improve consistency of ThreadContext API behavior
     new 6c8577a578 PR #704 from Carter but with fixes in StackLocator getCurrentStackTrace().
     new 9fdb34f077 This change fixes incorrect behavior of stack elements cache due to a change of data structure from LIFO to FIFO. This bug causes a major performance regression
     new 3003538519 Addressing PR feedback. Adding changelog item, fixing slow path in StackLocator and unit test for correct and wrong order of elements in the stack trace
     new 8060926461 Removing unneeded null check
     new ccbd99ebf6 Adding new unit and integration (for slow path in java8 StackLocator) tests for stack elements order
     new 2ae69a935f PR #1214 changelog

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../logging/log4j/util/StackLocatorTestIT.java     | 64 ++++++++++++++++
 .../logging/log4j/util/StackLocatorUtilTest.java   | 85 ++++++++++++++++++---
 .../util/PrivateSecurityManagerStackTraceUtil.java |  5 +-
 .../apache/logging/log4j/util/StackLocator.java    |  1 -
 .../log4j/core/impl/ThrowableProxyHelperTest.java  | 86 ++++++++++++++++++++++
 .../log4j/core/impl/ThrowableProxyHelper.java      |  6 +-
 .../1214_fix_stacktrace_order.xml}                 |  7 +-
 7 files changed, 234 insertions(+), 20 deletions(-)
 create mode 100644 log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorTestIT.java
 create mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelperTest.java
 copy src/changelog/{2.18.0/LOG4J2-3506_Support_Spring_2_6_x.xml => .2.x.x/1214_fix_stacktrace_order.xml} (75%)


[logging-log4j2] 02/06: This change fixes incorrect behavior of stack elements cache due to a change of data structure from LIFO to FIFO. This bug causes a major performance regression

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9fdb34f077e1c584b0b5737d03170fa4341667b7
Author: Aliaksei Dubrouski <ad...@linkedin.com>
AuthorDate: Tue Jan 17 10:16:50 2023 -0800

    This change fixes incorrect behavior of stack elements cache due to a change of data structure from LIFO to FIFO. This bug causes a major performance regression
---
 .../org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java
index 66b701447f..a3191d9140 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java
@@ -85,7 +85,7 @@ class ThrowableProxyHelper {
             stackLength = stackTrace.length;
         }
         final ExtendedStackTraceElement[] extStackTrace = new ExtendedStackTraceElement[stackLength];
-        Class<?> clazz = stack.isEmpty() ? null : stack.peek();
+        Class<?> clazz = stack.isEmpty() ? null : stack.peekLast();
         ClassLoader lastLoader = null;
         for (int i = stackLength - 1; i >= 0; --i) {
             final StackTraceElement stackTraceElement = stackTrace[i];
@@ -98,8 +98,8 @@ class ThrowableProxyHelper {
                 final CacheEntry entry = toCacheEntry(clazz, true);
                 extClassInfo = entry.element;
                 lastLoader = entry.loader;
-                stack.pop();
-                clazz = stack.isEmpty() ? null : stack.peek();
+                stack.pollLast();
+                clazz = stack.isEmpty() ? null : stack.peekLast();
             } else {
                 final CacheEntry cacheEntry = map.get(className);
                 if (cacheEntry != null) {


[logging-log4j2] 01/06: PR #704 from Carter but with fixes in StackLocator getCurrentStackTrace().

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6c8577a578d19b65e435d118deb9823f9f1ed659
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 17 18:31:42 2022 -0500

    PR #704 from Carter but with fixes in StackLocator
    getCurrentStackTrace().
    
    - Call push() one by one instead of addAll() to match log4j-api.
    - Do not allocate an extra collection.
    - Update the test.
    - Constants should be in upper case.
---
 .../logging/log4j/util/StackLocatorUtilTest.java   | 76 +++++++++++++++++++---
 .../util/PrivateSecurityManagerStackTraceUtil.java |  5 +-
 2 files changed, 68 insertions(+), 13 deletions(-)

diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
index 8fe11c3f8e..15ff9b0735 100644
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
+++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
@@ -16,14 +16,16 @@
  */
 package org.apache.logging.log4j.util;
 
-import java.util.ArrayDeque;
 import java.util.Deque;
 
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.engine.execution.InterceptingExecutableInvoker;
 import org.junit.jupiter.engine.execution.InvocationInterceptorChain;
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
 public class StackLocatorUtilTest {
 
@@ -75,15 +77,11 @@ public class StackLocatorUtilTest {
     @Test
     public void testGetCurrentStackTrace() throws Exception {
         final Deque<Class<?>> classes = StackLocatorUtil.getCurrentStackTrace();
-        final Deque<Class<?>> reversed = new ArrayDeque<>(classes.size());
-        while (!classes.isEmpty()) {
-            reversed.push(classes.pop());
+        while (classes.peekFirst() != StackLocatorUtil.class) {
+            classes.removeFirst();
         }
-        while (reversed.peek() != StackLocatorUtil.class) {
-            reversed.pop();
-        }
-        reversed.pop(); // ReflectionUtil
-        assertSame(StackLocatorUtilTest.class, reversed.pop());
+        classes.removeFirst(); // StackLocatorUtil
+        assertSame(StackLocatorUtilTest.class, classes.removeFirst());
     }
 
     @Test
@@ -112,4 +110,62 @@ public class StackLocatorUtilTest {
         assertEquals(this.getClass(), clazz, "Incorrect class");
     }
 
+    private final class Foo {
+
+        private StackTraceElement foo() {
+            return new Bar().bar(); // <--- testCalcLocation() line
+        }
+
+    }
+
+    private final class Bar {
+
+        private StackTraceElement bar() {
+            return baz();
+        }
+
+        private StackTraceElement baz() {
+            return quux();
+        }
+
+    }
+
+    private StackTraceElement quux() {
+        final StackLocator stackLocator = StackLocator.getInstance();
+        return stackLocator.calcLocation("org.apache.logging.log4j.util.StackLocatorUtilTest$Bar");
+    }
+
+    @Test
+    public void testCalcLocation() {
+        /*
+         * We are setting up a stack trace that looks like:
+         *  - org.apache.logging.log4j.util.test.StackLocatorTest#quux(line:118)
+         *  - org.apache.logging.log4j.util.test.StackLocatorTest$Bar#baz(line:112)
+         *  - org.apache.logging.log4j.util.test.StackLocatorTest$Bar#bar(line:108)
+         *  - org.apache.logging.log4j.util.test.StackLocatorTest$Foo(line:100)
+         *
+         * We are pretending that org.apache.logging.log4j.util.test.StackLocatorTest$Bar is the logging class, and
+         * org.apache.logging.log4j.util.test.StackLocatorTest$Foo is where the log line emanated.
+         */
+        final StackTraceElement element = new Foo().foo();
+        assertEquals("org.apache.logging.log4j.util.StackLocatorUtilTest$Foo", element.getClassName());
+        // The line number below may need adjustment if this file is changed.
+        assertEquals(116, element.getLineNumber());
+    }
+
+    @Test
+    public void testCalcLocationWhenNotInTheStack() {
+        final StackLocator stackLocator = StackLocator.getInstance();
+        final StackTraceElement stackTraceElement = stackLocator.calcLocation("java.util.Logger");
+        assertNull(stackTraceElement);
+    }
+
+    static class ClassLocator {
+
+        public Class<?> locateClass() {
+            final StackLocator stackLocator = StackLocator.getInstance();
+            return stackLocator.getCallerClass(ClassLocator.class);
+        }
+    }
+
 }
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PrivateSecurityManagerStackTraceUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PrivateSecurityManagerStackTraceUtil.java
index 2f2be07986..94ca4ff555 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PrivateSecurityManagerStackTraceUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PrivateSecurityManagerStackTraceUtil.java
@@ -17,6 +17,7 @@
 package org.apache.logging.log4j.util;
 
 import java.util.ArrayDeque;
+import java.util.Collections;
 import java.util.Deque;
 
 /**
@@ -64,9 +65,7 @@ final class PrivateSecurityManagerStackTraceUtil {
     static Deque<Class<?>> getCurrentStackTrace() {
         final Class<?>[] array = SECURITY_MANAGER.getClassContext();
         final Deque<Class<?>> classes = new ArrayDeque<>(array.length);
-        for (final Class<?> clazz : array) {
-            classes.push(clazz);
-        }
+        Collections.addAll(classes, array);
         return classes;
     }
 


[logging-log4j2] 06/06: PR #1214 changelog

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2ae69a935fcf0fa972f572ec5a06b37afc59bb29
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Mon Jan 30 18:52:18 2023 +0100

    PR #1214 changelog
---
 src/changelog/.2.x.x/1214_fix_stacktrace_order.xml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/changelog/.2.x.x/1214_fix_stacktrace_order.xml b/src/changelog/.2.x.x/1214_fix_stacktrace_order.xml
index baee854ae1..31aa67afe6 100644
--- a/src/changelog/.2.x.x/1214_fix_stacktrace_order.xml
+++ b/src/changelog/.2.x.x/1214_fix_stacktrace_order.xml
@@ -17,6 +17,7 @@
 -->
 <entry type="changed">
   <issue id="1214" link="https://github.com/apache/logging-log4j2/pull/1214"/>
-  <author id="vy"/>
-  <description format="asciidoc">Fixing the issue with stacktrace elements order which causes major regression due to cache misses</description>
+  <author id="alex-dubrouski" name="Aliaksei Durbouski"/>
+  <author id="ppkarwasz"/>
+  <description format="asciidoc">Fix order of stacktrace elements, that causes cache misses in `ThrowableProxyHelper`.</description>
 </entry>


[logging-log4j2] 03/06: Addressing PR feedback. Adding changelog item, fixing slow path in StackLocator and unit test for correct and wrong order of elements in the stack trace

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3003538519e8bfb06e99468f837d9495b9eb4f58
Author: Aliaksei Dubrouski <ad...@pandora.com>
AuthorDate: Wed Jan 18 16:21:39 2023 -0800

    Addressing PR feedback. Adding changelog item, fixing slow path in StackLocator and unit test for correct and wrong order of elements in the stack trace
---
 .../apache/logging/log4j/util/StackLocator.java    |  1 -
 .../log4j/core/impl/ThrowableProxyHelperTest.java  | 85 ++++++++++++++++++++++
 src/changelog/.2.x.x/1214_fix_stacktrace_order.xml | 22 ++++++
 3 files changed, 107 insertions(+), 1 deletion(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java
index a9f562cfda..5f68fc58f5 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocator.java
@@ -108,7 +108,6 @@ public final class StackLocator {
             s.forEach(f -> stack.add(f.getDeclaringClass()));
             return stack;
         });
-
     }
 
     public StackTraceElement calcLocation(final String fqcnOfLogger) {
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelperTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelperTest.java
new file mode 100644
index 0000000000..5575fb5473
--- /dev/null
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelperTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.logging.log4j.core.impl;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+/**
+ * Tests ThrowableProxyHelper.
+ */
+public class ThrowableProxyHelperTest {
+
+  /**
+   * We populate dummy stack trace and array of stack trace elements in the right order
+   * It supposed to always trigger fast path so cache won't be populated
+   * This simulates the case when current thread's and throwable stack traces have the same elements
+   */
+  @Test
+  public void testSuccessfulCacheHit() {
+    final Map<String, ThrowableProxyHelper.CacheEntry> map = new HashMap<>();
+    final Deque<Class<?>> stack = new ArrayDeque<>(3);
+    StackTraceElement[] stackTraceElements = new StackTraceElement[3];
+    stackTraceElements[0] = new StackTraceElement(Integer.class.getName(), "toString",
+          "Integer.java", 1);
+    stack.addLast(Integer.class);
+    stackTraceElements[1] = new StackTraceElement(Float.class.getName(), "toString",
+        "Float.java", 1);
+    stack.addLast(Float.class);
+    stackTraceElements[2] = new StackTraceElement(Double.class.getName(), "toString",
+        "Double.java", 1);
+    stack.addLast(Double.class);
+    final Throwable throwable = new IllegalStateException("This is a test");
+    final ThrowableProxy proxy = new ThrowableProxy(throwable);
+    ThrowableProxyHelper.toExtendedStackTrace(proxy, stack, map, null, stackTraceElements);
+    assertTrue(map.isEmpty());
+  }
+
+  /**
+   * We populate dummy stack trace and array of stack trace elements in the wrong order
+   * It will trigger fast path only once so cache will have two items
+   */
+  @Test
+  public void testFailedCacheHit() {
+    final Map<String, ThrowableProxyHelper.CacheEntry> map = new HashMap<>();
+    final Deque<Class<?>> stack = new ArrayDeque<>(3);
+    StackTraceElement[] stackTraceElements = new StackTraceElement[3];
+    stackTraceElements[0] = new StackTraceElement(Integer.class.getName(), "toString",
+        "Integer.java", 1);
+    stack.addFirst(Integer.class);
+    stackTraceElements[1] = new StackTraceElement(Float.class.getName(), "toString",
+        "Float.java", 1);
+    stack.addFirst(Float.class);
+    stackTraceElements[2] = new StackTraceElement(Double.class.getName(), "toString",
+        "Double.java", 1);
+    stack.addFirst(Double.class);
+    final Throwable throwable = new IllegalStateException("This is a test");
+    final ThrowableProxy proxy = new ThrowableProxy(throwable);
+    ThrowableProxyHelper.toExtendedStackTrace(proxy, stack, map, null, stackTraceElements);
+    assertFalse(map.isEmpty());
+    //Integer will match, so fast path won't cache it, only Float and Double will appear in cache after class loading
+    assertTrue(map.containsKey(Double.class.getName()));
+    assertTrue(map.containsKey(Float.class.getName()));
+  }
+
+}
diff --git a/src/changelog/.2.x.x/1214_fix_stacktrace_order.xml b/src/changelog/.2.x.x/1214_fix_stacktrace_order.xml
new file mode 100644
index 0000000000..baee854ae1
--- /dev/null
+++ b/src/changelog/.2.x.x/1214_fix_stacktrace_order.xml
@@ -0,0 +1,22 @@
+<?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 type="changed">
+  <issue id="1214" link="https://github.com/apache/logging-log4j2/pull/1214"/>
+  <author id="vy"/>
+  <description format="asciidoc">Fixing the issue with stacktrace elements order which causes major regression due to cache misses</description>
+</entry>


[logging-log4j2] 05/06: Adding new unit and integration (for slow path in java8 StackLocator) tests for stack elements order

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ccbd99ebf6a9a3165dfe5f6215137ec7b7a933a7
Author: Aliaksei Dubrouski <ad...@pandora.com>
AuthorDate: Thu Jan 19 16:32:00 2023 -0800

    Adding new unit and integration (for slow path in java8 StackLocator) tests for stack elements order
---
 .../logging/log4j/util/StackLocatorTestIT.java     | 64 ++++++++++++++++++++++
 .../logging/log4j/util/StackLocatorUtilTest.java   | 11 +++-
 .../log4j/core/impl/ThrowableProxyHelperTest.java  |  3 +-
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorTestIT.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorTestIT.java
new file mode 100644
index 0000000000..8219b674bd
--- /dev/null
+++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorTestIT.java
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.logging.log4j.util;
+
+import java.security.Permission;
+import java.util.Deque;
+
+import org.apache.logging.log4j.test.junit.SecurityManagerTestRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.parallel.ResourceLock;
+
+
+/**
+ * Tests https://github.com/apache/logging-log4j2/pull/1214.
+ * <p>
+ * Using a security manager can mess up other tests so this is best used from
+ * integration tests (classes that end in "IT" instead of "Test" and
+ * "TestCase".)
+ * </p>
+ *
+ * @see StackLocator
+ * @see SecurityManager
+ * @see System#setSecurityManager(SecurityManager)
+ */
+@ResourceLock("java.lang.SecurityManager")
+public class StackLocatorTestIT {
+  @Rule
+  public final SecurityManagerTestRule rule = new SecurityManagerTestRule(new TestSecurityManager());
+
+  /**
+   * Always throws a SecurityException for any reques to create a new SecurityManager
+   */
+  private static class TestSecurityManager extends SecurityManager {
+    @Override
+    public void checkPermission(final Permission permission) {
+      if ("createSecurityManager".equals(permission.getName())) {
+        throw new SecurityException();
+      }
+    }
+  }
+
+  @Test
+  public void testGetCurrentStacktraceSlowPath() {
+    final StackLocator stackLocator = StackLocator.getInstance();
+    final Deque<Class<?>> classes = stackLocator.getCurrentStackTrace();
+    Assertions.assertSame(StackLocator.class, classes.getFirst());
+  }
+}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
index 15ff9b0735..455ccc20f2 100644
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
+++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
@@ -84,6 +84,15 @@ public class StackLocatorUtilTest {
         assertSame(StackLocatorUtilTest.class, classes.removeFirst());
     }
 
+    @Test
+    public void testTopElementInStackTrace() {
+        final StackLocator stackLocator = StackLocator.getInstance();
+        final Deque<Class<?>> classes = stackLocator.getCurrentStackTrace();
+        //Removing private class in "PrivateSecurityManagerStackTraceUtil"
+        classes.removeFirst();
+        assertSame(PrivateSecurityManagerStackTraceUtil.class, classes.getFirst());
+    }
+
     @Test
     public void testGetCallerClassViaName() throws Exception {
         final Class<?> expected = InterceptingExecutableInvoker.class;
@@ -150,7 +159,7 @@ public class StackLocatorUtilTest {
         final StackTraceElement element = new Foo().foo();
         assertEquals("org.apache.logging.log4j.util.StackLocatorUtilTest$Foo", element.getClassName());
         // The line number below may need adjustment if this file is changed.
-        assertEquals(116, element.getLineNumber());
+        assertEquals(125, element.getLineNumber());
     }
 
     @Test
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelperTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelperTest.java
index 5575fb5473..628650261b 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelperTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelperTest.java
@@ -20,10 +20,11 @@ import java.util.ArrayDeque;
 import java.util.Deque;
 import java.util.HashMap;
 import java.util.Map;
+
 import org.junit.Test;
 
-import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
  * Tests ThrowableProxyHelper.


[logging-log4j2] 04/06: Removing unneeded null check

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 806092646125b9e71a56557045215951fe32e88f
Author: Aliaksei Dubrouski <ad...@pandora.com>
AuthorDate: Wed Jan 18 16:25:38 2023 -0800

    Removing unneeded null check
---
 .../java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java
index a3191d9140..6f3ae3e46d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxyHelper.java
@@ -99,7 +99,7 @@ class ThrowableProxyHelper {
                 extClassInfo = entry.element;
                 lastLoader = entry.loader;
                 stack.pollLast();
-                clazz = stack.isEmpty() ? null : stack.peekLast();
+                clazz = stack.peekLast();
             } else {
                 final CacheEntry cacheEntry = map.get(className);
                 if (cacheEntry != null) {