You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2019/06/23 02:53:44 UTC

[logging-log4j2] 02/02: LOG4J2-2633 - Handle NoSuchElementException

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

rgoers pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 71fd036e0bbc40598b72676854b2827565b44836
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sat Jun 22 19:53:32 2019 -0700

    LOG4J2-2633 - Handle NoSuchElementException
---
 .../org/apache/logging/log4j/util/StackLocatorUtil.java    | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java
index 56812fe..84cc689 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/StackLocatorUtil.java
@@ -16,13 +16,17 @@
  */
 package org.apache.logging.log4j.util;
 
+import java.util.NoSuchElementException;
 import java.util.Stack;
 
+import org.apache.logging.log4j.status.StatusLogger;
+
 /**
  * <em>Consider this class private.</em> Provides various methods to determine the caller class. <h3>Background</h3>
  */
 public final class StackLocatorUtil {
     private static StackLocator stackLocator = null;
+    private static volatile boolean errorLogged = false;
 
     static {
         stackLocator = StackLocator.getInstance();
@@ -68,6 +72,14 @@ public final class StackLocatorUtil {
     }
 
     public static StackTraceElement calcLocation(final String fqcnOfLogger) {
-        return stackLocator.calcLocation(fqcnOfLogger);
+        try {
+            return stackLocator.calcLocation(fqcnOfLogger);
+        } catch (NoSuchElementException ex) {
+            if (!errorLogged) {
+                errorLogged = true;
+                StatusLogger.getLogger().warn("Unable to locate stack trace element for {}", fqcnOfLogger, ex);
+            }
+            return null;
+        }
     }
 }