You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/21 19:09:31 UTC

[2/8] git commit: Use ReflectionUtil.getCurrentStackTrace()

Use ReflectionUtil.getCurrentStackTrace()


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/066fb893
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/066fb893
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/066fb893

Branch: refs/heads/master
Commit: 066fb8936943cae9631413625290e9e0fdd17c97
Parents: 3d76316
Author: Matt Sicker <ma...@apache.org>
Authored: Fri Sep 5 16:53:20 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Fri Sep 5 16:53:20 2014 -0500

----------------------------------------------------------------------
 .../logging/log4j/core/impl/ThrowableProxy.java | 64 +-------------------
 1 file changed, 2 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/066fb893/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
index 2320ad7..8d6f9f3 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
@@ -25,10 +25,10 @@ import java.util.List;
 import java.util.Map;
 import java.util.Stack;
 
-import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.util.Loader;
 import org.apache.logging.log4j.core.util.Throwables;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.ReflectionUtil;
 import org.apache.logging.log4j.util.Strings;
 
 /**
@@ -61,45 +61,12 @@ public class ThrowableProxy implements Serializable {
         }
     }
 
-    /**
-     * Security Manager for accessing the call stack.
-     */
-    private static class PrivateSecurityManager extends SecurityManager {
-        public Class<?>[] getClasses() {
-            return this.getClassContext();
-        }
-    }
-
     private static final ThrowableProxy[] EMPTY_THROWABLE_PROXY_ARRAY = new ThrowableProxy[0];
 
     private static final char EOL = '\n';
 
-    private static final Logger LOGGER = StatusLogger.getLogger();
-
-    private static final PrivateSecurityManager SECURITY_MANAGER;
-
     private static final long serialVersionUID = -2752771578252251910L;
 
-    static {
-        if (ReflectiveCallerClassUtility.isSupported()) {
-            SECURITY_MANAGER = null;
-        } else {
-            PrivateSecurityManager securityManager;
-            try {
-                securityManager = new PrivateSecurityManager();
-                if (securityManager.getClasses() == null) {
-                    // This shouldn't happen.
-                    securityManager = null;
-                    LOGGER.error("Unable to obtain call stack from security manager.");
-                }
-            } catch (final Exception e) {
-                securityManager = null;
-                LOGGER.debug("Unable to install security manager.", e);
-            }
-            SECURITY_MANAGER = securityManager;
-        }
-    }
-
     private final ThrowableProxy causeProxy;
 
     private int commonElementCount;
@@ -142,7 +109,7 @@ public class ThrowableProxy implements Serializable {
         this.message = throwable.getMessage();
         this.localizedMessage = throwable.getLocalizedMessage();
         final Map<String, CacheEntry> map = new HashMap<String, CacheEntry>();
-        final Stack<Class<?>> stack = this.getCurrentStack();
+        final Stack<Class<?>> stack = ReflectionUtil.getCurrentStackTrace();
         this.extendedStackTrace = this.toExtendedStackTrace(stack, map, null, throwable.getStackTrace());
         final Throwable throwableCause = throwable.getCause();
         this.causeProxy = throwableCause == null ? null : new ThrowableProxy(throwable, stack, map, throwableCause);
@@ -339,33 +306,6 @@ public class ThrowableProxy implements Serializable {
     }
 
     /**
-     * Initialize the cache by resolving everything in the current stack trace via Reflection.getCallerClass or via the
-     * SecurityManager if either are available. These are the only Classes that can be trusted to be accurate.
-     * 
-     * @return A Stack containing the current stack of Class objects.
-     */
-    private Stack<Class<?>> getCurrentStack() {
-        if (ReflectiveCallerClassUtility.isSupported()) {
-            final Stack<Class<?>> classes = new Stack<Class<?>>();
-            int index = 1;
-            Class<?> clazz = ReflectiveCallerClassUtility.getCaller(index);
-            while (clazz != null) {
-                classes.push(clazz);
-                clazz = ReflectiveCallerClassUtility.getCaller(++index);
-            }
-            return classes;
-        } else if (SECURITY_MANAGER != null) {
-            final Class<?>[] array = SECURITY_MANAGER.getClasses();
-            final Stack<Class<?>> classes = new Stack<Class<?>>();
-            for (final Class<?> clazz : array) {
-                classes.push(clazz);
-            }
-            return classes;
-        }
-        return new Stack<Class<?>>();
-    }
-
-    /**
      * Gets the stack trace including packaging information.
      * 
      * @return The stack trace including packaging information.