You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2014/05/24 09:28:20 UTC
svn commit: r1597261 - in
/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core:
impl/ jackson/
Author: ggregory
Date: Sat May 24 07:28:20 2014
New Revision: 1597261
URL: http://svn.apache.org/r1597261
Log:
Finish the throwable proxy rework:
- Go back to the design that had the class and package information for a Class in a standalone class, now called ExtendedClassInfo.
- The ExtendedStackTraceElement now has a cleaner design: it holds a JRE StackTraceElement and a ExtendedClassInfo.
- The ThrowableProxy can now go back to caching ExtendedClassInfo instead of ExtendedStackTraceElement, which did to track a stack trace correctly anyway because ExtendedStackTraceElement was reused instead of just the extra class info.
- Rename StackTracePackageElementMixIn to ExtendedStackTraceElementMixIn.
- I wonder if this fixes [LOG4J2-651] Log4j 2 throws ArrayIndexOutOfBoundsException. Perhaps this was already fixed.
Added:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java (with props)
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java
- copied, changed from r1597255, logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTracePackageElementMixIn.java
Removed:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTracePackageElementMixIn.java
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java
Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java?rev=1597261&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java Sat May 24 07:28:20 2014
@@ -0,0 +1,116 @@
+/*
+ * 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.io.Serializable;
+
+/**
+ * Class and package data used with a {@link StackTraceElement} in a {@link ExtendedStackTraceElement}.
+ */
+public final class ExtendedClassInfo implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final boolean exact;
+
+ private final String location;
+
+ private final String version;
+
+ /**
+ * Constructs a new instance.
+ *
+ * @param exact
+ * @param location
+ * @param version
+ */
+ public ExtendedClassInfo(final boolean exact, final String location, final String version) {
+ super();
+ this.exact = exact;
+ this.location = location;
+ this.version = version;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof ExtendedClassInfo)) {
+ return false;
+ }
+ final ExtendedClassInfo other = (ExtendedClassInfo) obj;
+ if (this.exact != other.exact) {
+ return false;
+ }
+ if (this.location == null) {
+ if (other.location != null) {
+ return false;
+ }
+ } else if (!this.location.equals(other.location)) {
+ return false;
+ }
+ if (this.version == null) {
+ if (other.version != null) {
+ return false;
+ }
+ } else if (!this.version.equals(other.version)) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean getExact() {
+ return this.exact;
+ }
+
+ public String getLocation() {
+ return this.location;
+ }
+
+ public String getVersion() {
+ return this.version;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (this.exact ? 1231 : 1237);
+ result = prime * result + ((this.location == null) ? 0 : this.location.hashCode());
+ result = prime * result + ((this.version == null) ? 0 : this.version.hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ if (!this.exact) {
+ sb.append('~');
+ }
+ sb.append('[');
+ sb.append(this.location);
+ sb.append(':');
+ sb.append(this.version);
+ sb.append(']');
+ return sb.toString();
+ }
+
+}
\ No newline at end of file
Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedClassInfo.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java?rev=1597261&r1=1597260&r2=1597261&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ExtendedStackTraceElement.java Sat May 24 07:28:20 2014
@@ -18,8 +18,6 @@ package org.apache.logging.log4j.core.im
import java.io.Serializable;
-import org.apache.logging.log4j.util.Strings;
-
import sun.reflect.Reflection;
/**
@@ -33,37 +31,26 @@ import sun.reflect.Reflection;
* </ul>
* </p>
*/
-public class ExtendedStackTraceElement implements Serializable {
+public final class ExtendedStackTraceElement implements Serializable {
private static final long serialVersionUID = -2171069569241280505L;
- private final boolean exact;
-
- private final String location;
+ private final ExtendedClassInfo extraClassInfo;
private final StackTraceElement stackTraceElement;
- private final String version;
-
- /**
- * Constructor that takes the location, version, and exact match flag.
- *
- * @param stackTraceElement TODO
- * @param exact if true this is an exact package element.
- * @param location The location of the Class.
- * @param version The version of the component.
- */
- public ExtendedStackTraceElement(final StackTraceElement stackTraceElement, final boolean exact, final String location,
- final String version) {
+ public ExtendedStackTraceElement(final StackTraceElement stackTraceElement, final ExtendedClassInfo extraClassInfo) {
this.stackTraceElement = stackTraceElement;
- this.location = location;
- this.version = version;
- this.exact = exact;
+ this.extraClassInfo = extraClassInfo;
}
- public ExtendedStackTraceElement(final String declaringClass, final String methodName, final String fileName, final int lineNumber,
- final boolean exact, final String location, final String version) {
- this(new StackTraceElement(declaringClass, methodName, fileName, lineNumber), exact, location, version);
+ /**
+ * Called from Jackson for XML and JSON IO.
+ */
+ public ExtendedStackTraceElement(final String declaringClass, final String methodName, final String fileName,
+ final int lineNumber, final boolean exact, final String location, final String version) {
+ this(new StackTraceElement(declaringClass, methodName, fileName, lineNumber), new ExtendedClassInfo(exact,
+ location, version));
}
@Override
@@ -78,14 +65,11 @@ public class ExtendedStackTraceElement i
return false;
}
final ExtendedStackTraceElement other = (ExtendedStackTraceElement) obj;
- if (this.exact != other.exact) {
- return false;
- }
- if (this.location == null) {
- if (other.location != null) {
+ if (this.extraClassInfo == null) {
+ if (other.extraClassInfo != null) {
return false;
}
- } else if (!this.location.equals(other.location)) {
+ } else if (!this.extraClassInfo.equals(other.extraClassInfo)) {
return false;
}
if (this.stackTraceElement == null) {
@@ -95,62 +79,19 @@ public class ExtendedStackTraceElement i
} else if (!this.stackTraceElement.equals(other.stackTraceElement)) {
return false;
}
- if (this.version == null) {
- if (other.version != null) {
- return false;
- }
- } else if (!this.version.equals(other.version)) {
- return false;
- }
return true;
}
- /**
- * Returns the indicator of whether this is an exact match.
- *
- * @return true if the location was determined exactly.
- */
- public boolean getExact() {
- return this.exact;
- }
-
- /**
- * Returns the location of the element.
- *
- * @return The location of the element.
- */
- public String getLocation() {
- return this.location;
- }
-
- public StackTraceElement getStackTraceElement() {
- return this.stackTraceElement;
- }
-
- /**
- * Returns the version of the element.
- *
- * @return the version of the element.
- */
- public String getVersion() {
- return this.version;
+ public String getClassName() {
+ return this.stackTraceElement.getClassName();
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + (this.exact ? 1231 : 1237);
- result = prime * result + (this.location == null ? 0 : this.location.hashCode());
- result = prime * result + (this.version == null ? 0 : this.version.hashCode());
- result = prime * result + (this.stackTraceElement == null ? 0 : this.stackTraceElement.hashCode());
- return result;
+ public boolean getExact() {
+ return this.extraClassInfo.getExact();
}
- @Override
- public String toString() {
- final String exactStr = this.exact ? Strings.EMPTY : "~";
- return exactStr + '[' + this.location + ':' + this.version + ']';
+ public ExtendedClassInfo getExtraClassInfo() {
+ return this.extraClassInfo;
}
public String getFileName() {
@@ -161,15 +102,41 @@ public class ExtendedStackTraceElement i
return this.stackTraceElement.getLineNumber();
}
- public String getClassName() {
- return this.stackTraceElement.getClassName();
+ public String getLocation() {
+ return this.extraClassInfo.getLocation();
}
public String getMethodName() {
return this.stackTraceElement.getMethodName();
}
+ public StackTraceElement getStackTraceElement() {
+ return this.stackTraceElement;
+ }
+
+ public String getVersion() {
+ return this.extraClassInfo.getVersion();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((this.extraClassInfo == null) ? 0 : this.extraClassInfo.hashCode());
+ result = prime * result + ((this.stackTraceElement == null) ? 0 : this.stackTraceElement.hashCode());
+ return result;
+ }
+
public boolean isNativeMethod() {
return this.stackTraceElement.isNativeMethod();
}
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append(this.stackTraceElement);
+ sb.append(" ");
+ sb.append(this.extraClassInfo);
+ return sb.toString();
+ }
}
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java?rev=1597261&r1=1597260&r2=1597261&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java Sat May 24 07:28:20 2014
@@ -33,15 +33,15 @@ import org.apache.logging.log4j.util.Str
/**
* Wraps a Throwable to add packaging information about each stack trace element.
- *
+ *
* <p>
- * A proxy is used to represent a throwable that may not exist in a different class loader or JVM. When an application deserializes a
- * ThrowableProxy, the throwable may not be set, but the throwable's information is preserved in other fields of the proxy like the message
- * and stack trace.
+ * A proxy is used to represent a throwable that may not exist in a different class loader or JVM. When an application
+ * deserializes a ThrowableProxy, the throwable may not be set, but the throwable's information is preserved in other
+ * fields of the proxy like the message and stack trace.
* </p>
- *
- * TODO: Move this class to org.apache.logging.log4j.core because it is used from LogEvent.
- * TODO: Deserialize: Try to rebuild Throwable if the target exception is in this class loader?
+ *
+ * TODO: Move this class to org.apache.logging.log4j.core because it is used from LogEvent. TODO: Deserialize: Try to
+ * rebuild Throwable if the target exception is in this class loader?
*/
public class ThrowableProxy implements Serializable {
@@ -52,10 +52,10 @@ public class ThrowableProxy implements S
* </p>
*/
static class CacheEntry {
- private final ExtendedStackTraceElement element;
+ private final ExtendedClassInfo element;
private final ClassLoader loader;
- public CacheEntry(final ExtendedStackTraceElement element, final ClassLoader loader) {
+ public CacheEntry(final ExtendedClassInfo element, final ClassLoader loader) {
this.element = element;
this.loader = loader;
}
@@ -132,8 +132,9 @@ public class ThrowableProxy implements S
/**
* Constructs the wrapper for the Throwable that includes packaging data.
- *
- * @param throwable The Throwable to wrap, must not be null.
+ *
+ * @param throwable
+ * The Throwable to wrap, must not be null.
*/
public ThrowableProxy(final Throwable throwable) {
this.throwable = throwable;
@@ -150,13 +151,18 @@ public class ThrowableProxy implements S
/**
* Constructs the wrapper for a Throwable that is referenced as the cause by another Throwable.
- *
- * @param parent The Throwable referencing this Throwable.
- * @param stack The Class stack.
- * @param map The cache containing the packaging data.
- * @param cause The Throwable to wrap.
+ *
+ * @param parent
+ * The Throwable referencing this Throwable.
+ * @param stack
+ * The Class stack.
+ * @param map
+ * The cache containing the packaging data.
+ * @param cause
+ * The Throwable to wrap.
*/
- private ThrowableProxy(final Throwable parent, final Stack<Class<?>> stack, final Map<String, CacheEntry> map, final Throwable cause) {
+ private ThrowableProxy(final Throwable parent, final Stack<Class<?>> stack, final Map<String, CacheEntry> map,
+ final Throwable cause) {
this.throwable = cause;
this.name = cause.getClass().getName();
this.message = this.throwable.getMessage();
@@ -207,7 +213,8 @@ public class ThrowableProxy implements S
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void formatCause(final StringBuilder sb, final ThrowableProxy cause, final List<String> ignorePackages) {
sb.append("Caused by: ").append(cause).append(EOL);
- this.formatElements(sb, cause.commonElementCount, cause.getThrowable().getStackTrace(), cause.extendedStackTrace, ignorePackages);
+ this.formatElements(sb, cause.commonElementCount, cause.getThrowable().getStackTrace(),
+ cause.extendedStackTrace, ignorePackages);
if (cause.getCauseProxy() != null) {
this.formatCause(sb, cause.causeProxy, ignorePackages);
}
@@ -249,19 +256,20 @@ public class ThrowableProxy implements S
}
}
- private void formatEntry(final StackTraceElement element, final ExtendedStackTraceElement extStackTraceElement, final StringBuilder sb) {
+ private void formatEntry(final StackTraceElement element, final ExtendedStackTraceElement extStackTraceElement,
+ final StringBuilder sb) {
sb.append("\tat ");
- sb.append(element);
- sb.append(' ');
sb.append(extStackTraceElement);
sb.append('\n');
}
/**
* Formats the specified Throwable.
- *
- * @param sb StringBuilder to contain the formatted Throwable.
- * @param cause The Throwable to format.
+ *
+ * @param sb
+ * StringBuilder to contain the formatted Throwable.
+ * @param cause
+ * The Throwable to format.
*/
public void formatWrapper(final StringBuilder sb, final ThrowableProxy cause) {
this.formatWrapper(sb, cause, null);
@@ -269,10 +277,13 @@ public class ThrowableProxy implements S
/**
* Formats the specified Throwable.
- *
- * @param sb StringBuilder to contain the formatted Throwable.
- * @param cause The Throwable to format.
- * @param packages The List of packages to be suppressed from the trace.
+ *
+ * @param sb
+ * StringBuilder to contain the formatted Throwable.
+ * @param cause
+ * The Throwable to format.
+ * @param packages
+ * The List of packages to be suppressed from the trace.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void formatWrapper(final StringBuilder sb, final ThrowableProxy cause, final List<String> packages) {
@@ -282,7 +293,8 @@ public class ThrowableProxy implements S
sb.append("Wrapped by: ");
}
sb.append(cause).append('\n');
- this.formatElements(sb, cause.commonElementCount, cause.getThrowable().getStackTrace(), cause.extendedStackTrace, packages);
+ this.formatElements(sb, cause.commonElementCount, cause.getThrowable().getStackTrace(),
+ cause.extendedStackTrace, packages);
}
public ThrowableProxy getCauseProxy() {
@@ -291,7 +303,7 @@ public class ThrowableProxy implements S
/**
* Format the Throwable that is the cause of this Throwable.
- *
+ *
* @return The formatted Throwable that caused this Throwable.
*/
public String getCauseStackTraceAsString() {
@@ -300,8 +312,9 @@ public class ThrowableProxy implements S
/**
* Format the Throwable that is the cause of this Throwable.
- *
- * @param packages The List of packages to be suppressed from the trace.
+ *
+ * @param packages
+ * The List of packages to be suppressed from the trace.
* @return The formatted Throwable that caused this Throwable.
*/
public String getCauseStackTraceAsString(final List<String> packages) {
@@ -317,8 +330,9 @@ public class ThrowableProxy implements S
}
/**
- * Return the number of elements that are being omitted because they are common with the parent Throwable's stack trace.
- *
+ * Return the number of elements that are being omitted because they are common with the parent Throwable's stack
+ * trace.
+ *
* @return The number of elements omitted from the stack trace.
*/
public int getCommonElementCount() {
@@ -326,9 +340,9 @@ public class ThrowableProxy implements S
}
/**
- * 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.
- *
+ * 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() {
@@ -354,7 +368,7 @@ public class ThrowableProxy implements S
/**
* Gets the stack trace including packaging information.
- *
+ *
* @return The stack trace including packaging information.
*/
public ExtendedStackTraceElement[] getExtendedStackTrace() {
@@ -363,7 +377,7 @@ public class ThrowableProxy implements S
/**
* Format the stack trace including packaging information.
- *
+ *
* @return The formatted stack trace including packaging information.
*/
public String getExtendedStackTraceAsString() {
@@ -372,8 +386,9 @@ public class ThrowableProxy implements S
/**
* Format the stack trace including packaging information.
- *
- * @param ignorePackages List of packages to be ignored in the trace.
+ *
+ * @param ignorePackages
+ * List of packages to be ignored in the trace.
* @return The formatted stack trace including packaging information.
*/
public String getExtendedStackTraceAsString(final List<String> ignorePackages) {
@@ -400,7 +415,7 @@ public class ThrowableProxy implements S
/**
* Return the FQCN of the Throwable.
- *
+ *
* @return The FQCN of the Throwable.
*/
public String getName() {
@@ -413,7 +428,7 @@ public class ThrowableProxy implements S
/**
* Gets proxies for suppressed exceptions.
- *
+ *
* @return proxies for suppressed exceptions.
*/
public ThrowableProxy[] getSuppressedProxies() {
@@ -422,7 +437,7 @@ public class ThrowableProxy implements S
/**
* Format the suppressed Throwables.
- *
+ *
* @return The formatted suppressed Throwables.
*/
public String getSuppressedStackTrace() {
@@ -439,7 +454,7 @@ public class ThrowableProxy implements S
/**
* The throwable or null if this object is deserialized from XML or JSON.
- *
+ *
* @return The throwable or null if this object is deserialized from XML or JSON.
*/
public Throwable getThrowable() {
@@ -470,9 +485,11 @@ public class ThrowableProxy implements S
/**
* Loads classes not located via Reflection.getCallerClass.
- *
- * @param lastLoader The ClassLoader that loaded the Class that called this Class.
- * @param className The name of the Class.
+ *
+ * @param lastLoader
+ * The ClassLoader that loaded the Class that called this Class.
+ * @param className
+ * The name of the Class.
* @return The Class object for the Class or null if it could not be located.
*/
private Class<?> loadClass(final ClassLoader lastLoader, final String className) {
@@ -502,14 +519,18 @@ public class ThrowableProxy implements S
/**
* Construct the CacheEntry from the Class's information.
- *
- * @param stackTraceElement The stack trace element
- * @param callerClass The Class.
- * @param exact True if the class was obtained via Reflection.getCallerClass.
- *
+ *
+ * @param stackTraceElement
+ * The stack trace element
+ * @param callerClass
+ * The Class.
+ * @param exact
+ * True if the class was obtained via Reflection.getCallerClass.
+ *
* @return The CacheEntry.
*/
- private CacheEntry resolvePackageElement(final StackTraceElement stackTraceElement, final Class<?> callerClass, final boolean exact) {
+ private CacheEntry toCacheEntry(final StackTraceElement stackTraceElement, final Class<?> callerClass,
+ final boolean exact) {
String location = "?";
String version = "?";
ClassLoader lastLoader = null;
@@ -541,16 +562,20 @@ public class ThrowableProxy implements S
}
lastLoader = callerClass.getClassLoader();
}
- return new CacheEntry(new ExtendedStackTraceElement(stackTraceElement, exact, location, version), lastLoader);
+ return new CacheEntry(new ExtendedClassInfo(exact, location, version), lastLoader);
}
/**
* Resolve all the stack entries in this stack trace that are not common with the parent.
- *
- * @param stack The callers Class stack.
- * @param map The cache of CacheEntry objects.
- * @param rootTrace The first stack trace resolve or null.
- * @param stackTrace The stack trace being resolved.
+ *
+ * @param stack
+ * The callers Class stack.
+ * @param map
+ * The cache of CacheEntry objects.
+ * @param rootTrace
+ * The first stack trace resolve or null.
+ * @param stackTrace
+ * The stack trace being resolved.
* @return The StackTracePackageElement array.
*/
ExtendedStackTraceElement[] toExtendedStackTrace(final Stack<Class<?>> stack, final Map<String, CacheEntry> map,
@@ -569,39 +594,42 @@ public class ThrowableProxy implements S
this.commonElementCount = 0;
stackLength = stackTrace.length;
}
- final ExtendedStackTraceElement[] packageArray = new ExtendedStackTraceElement[stackLength];
+ final ExtendedStackTraceElement[] extStackTrace = new ExtendedStackTraceElement[stackLength];
Class<?> clazz = stack.isEmpty() ? null : stack.peek();
ClassLoader lastLoader = null;
for (int i = stackLength - 1; i >= 0; --i) {
final StackTraceElement stackTraceElement = stackTrace[i];
final String className = stackTraceElement.getClassName();
- // The stack returned from getCurrentStack will be missing entries for java.lang.reflect.Method.invoke()
+ // The stack returned from getCurrentStack may be missing entries for java.lang.reflect.Method.invoke()
// and its implementation. The Throwable might also contain stack entries that are no longer
// present as those methods have returned.
+ ExtendedClassInfo extClassInfo;
if (clazz != null && className.equals(clazz.getName())) {
- final CacheEntry entry = this.resolvePackageElement(stackTraceElement, clazz, true);
- packageArray[i] = entry.element;
+ final CacheEntry entry = this.toCacheEntry(stackTraceElement, clazz, true);
+ extClassInfo = entry.element;
lastLoader = entry.loader;
stack.pop();
clazz = stack.isEmpty() ? null : stack.peek();
} else {
if (map.containsKey(className)) {
final CacheEntry entry = map.get(className);
- packageArray[i] = entry.element;
+ extClassInfo = entry.element;
if (entry.loader != null) {
lastLoader = entry.loader;
}
} else {
- final CacheEntry entry = this.resolvePackageElement(stackTraceElement, this.loadClass(lastLoader, className), false);
- packageArray[i] = entry.element;
- map.put(className, entry);
+ final CacheEntry entry = this.toCacheEntry(stackTraceElement,
+ this.loadClass(lastLoader, className), false);
+ extClassInfo = entry.element;
+ map.put(stackTraceElement.toString(), entry);
if (entry.loader != null) {
lastLoader = entry.loader;
}
}
}
+ extStackTrace[i] = new ExtendedStackTraceElement(stackTraceElement, extClassInfo);
}
- return packageArray;
+ return extStackTrace;
}
@Override
Copied: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java (from r1597255, logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTracePackageElementMixIn.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java?p2=logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java&p1=logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTracePackageElementMixIn.java&r1=1597255&r2=1597261&rev=1597261&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/StackTracePackageElementMixIn.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/ExtendedStackTraceElementMixIn.java Sat May 24 07:28:20 2014
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.ja
import java.io.Serializable;
+import org.apache.logging.log4j.core.impl.ExtendedClassInfo;
import org.apache.logging.log4j.core.impl.ExtendedStackTraceElement;
import com.fasterxml.jackson.annotation.JsonCreator;
@@ -30,12 +31,12 @@ import com.fasterxml.jackson.dataformat.
* Mix-in for {@link ExtendedStackTraceElement}.
*/
@JsonPropertyOrder({ "class", "method", "file", "line", "exact", "location", "version" })
-abstract class StackTracePackageElementMixIn implements Serializable {
+abstract class ExtendedStackTraceElementMixIn implements Serializable {
private static final long serialVersionUID = 1L;
@JsonCreator
- public StackTracePackageElementMixIn(
+ public ExtendedStackTraceElementMixIn(
// @formatter:off
@JsonProperty("class") final String declaringClass,
@JsonProperty("method") final String methodName,
@@ -57,6 +58,9 @@ abstract class StackTracePackageElementM
@JacksonXmlProperty(isAttribute = true)
public abstract boolean getExact();
+ @JsonIgnore
+ public abstract ExtendedClassInfo getExtraClassInfo();
+
@JsonProperty("file")
@JacksonXmlProperty(localName = "file", isAttribute = true)
public abstract String getFileName();
@@ -72,7 +76,7 @@ abstract class StackTracePackageElementM
@JsonProperty("method")
@JacksonXmlProperty(localName = "method", isAttribute = true)
public abstract String getMethodName();
-
+
@JsonIgnore
abstract StackTraceElement getStackTraceElement();
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java?rev=1597261&r1=1597260&r2=1597261&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java Sat May 24 07:28:20 2014
@@ -47,7 +47,7 @@ class Initializers {
context.setMixInAnnotations(Level.class, LevelMixIn.class);
context.setMixInAnnotations(LogEvent.class, LogEventMixIn.class);
// Log4j Core classes: we do not want to bring in Jackson at runtime if we do not have to.
- context.setMixInAnnotations(ExtendedStackTraceElement.class, StackTracePackageElementMixIn.class);
+ context.setMixInAnnotations(ExtendedStackTraceElement.class, ExtendedStackTraceElementMixIn.class);
context.setMixInAnnotations(ThrowableProxy.class, ThrowableProxyMixIn.class);
}
}