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 2022/02/05 20:09:12 UTC
[logging-log4j2] branch release-2.x updated: Log4j 1.2 bridge missing some ThrowableInformation constructors.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new b3bbc3b Log4j 1.2 bridge missing some ThrowableInformation constructors.
b3bbc3b is described below
commit b3bbc3b5a3987c793d84faf066454af1fab43a10
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 5 15:09:08 2022 -0500
Log4j 1.2 bridge missing some ThrowableInformation constructors.
---
.../org/apache/log4j/spi/ThrowableInformation.java | 42 ++++++++++++++++++----
src/changes/changes.xml | 3 ++
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/ThrowableInformation.java b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/ThrowableInformation.java
index 898eb9c..b61b17d 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/ThrowableInformation.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/ThrowableInformation.java
@@ -16,27 +16,42 @@
*/
package org.apache.log4j.spi;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
+import org.apache.log4j.Category;
import org.apache.logging.log4j.util.Strings;
/**
- * Class Description goes here.
+ * Log4j's internal representation of throwables.
*/
public class ThrowableInformation implements java.io.Serializable {
static final long serialVersionUID = -4748765566864322735L;
private transient Throwable throwable;
+ private transient Category category;
+ private String[] rep;
private Method toStringList;
- public ThrowableInformation(Throwable throwable) {
+ /**
+ * Constructs new instance.
+ *
+ * @since 1.2.15
+ * @param r String representation of throwable.
+ */
+ public ThrowableInformation(final String[] r) {
+ this.rep = rep != null ? r.clone() : null;
+ }
+
+ /**
+ * Constructs new instance.
+ */
+ public ThrowableInformation(final Throwable throwable) {
this.throwable = throwable;
Method method = null;
try {
- Class<?> throwables = Class.forName("org.apache.logging.log4j.core.util.Throwables");
+ final Class<?> throwables = Class.forName("org.apache.logging.log4j.core.util.Throwables");
method = throwables.getMethod("toStringList", Throwable.class);
} catch (ClassNotFoundException | NoSuchMethodException ex) {
// Ignore the exception if Log4j-core is not present.
@@ -44,6 +59,19 @@ public class ThrowableInformation implements java.io.Serializable {
this.toStringList = method;
}
+ /**
+ * Constructs a new instance.
+ *
+ * @param throwable throwable, may not be null.
+ * @param category category used to obtain ThrowableRenderer, may be null.
+ * @since 1.2.16
+ */
+ public ThrowableInformation(final Throwable throwable, final Category category) {
+ this(throwable);
+ this.category = category;
+ this.rep = null;
+ }
+
public Throwable getThrowable() {
return throwable;
}
@@ -52,15 +80,15 @@ public class ThrowableInformation implements java.io.Serializable {
if (toStringList != null && throwable != null) {
try {
@SuppressWarnings("unchecked")
+ final
List<String> elements = (List<String>) toStringList.invoke(null, throwable);
if (elements != null) {
return elements.toArray(Strings.EMPTY_ARRAY);
}
- } catch (IllegalAccessException | InvocationTargetException ex) {
+ } catch (final ReflectiveOperationException ex) {
// Ignore the exception.
}
}
- return null;
+ return rep;
}
}
-
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a7f3e17..5dbc8d4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -166,6 +166,9 @@
<action dev="ggregory" type="fix" due-to="Gary Gregory">
Log4j 1.2 bridge missing DefaultThrowableRenderer.
</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">
+ Log4j 1.2 bridge missing some ThrowableInformation constructors.
+ </action>
<action dev="ggregory" type="fix">
JndiManager reverts to 2.17.0 behavior: Read the system property for each call.
</action>