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 2022/03/29 14:05:30 UTC
[logging-log4j2] 10/25: Log4j 1.2 bridge missing some ThrowableInformation constructors.
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 2f430add5a645bd263e0f345aeae1eb8a0f52d93
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 5 15:09:08 2022 -0500
Log4j 1.2 bridge missing some ThrowableInformation constructors.
Conflicts:
log4j-1.2-api/src/main/java/org/apache/log4j/spi/ThrowableInformation.java
---
.../org/apache/log4j/spi/ThrowableInformation.java | 46 +++++++++++++++++-----
src/changes/changes.xml | 3 ++
2 files changed, 39 insertions(+), 10 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 e9c9776..de81a1a 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,29 +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.core.util.Throwables;
/**
- * 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 final Method toStringList;
+ private transient Category category;
+ private String[] rep;
+ private Method toStringList;
- @SuppressWarnings("unchecked")
- 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(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.
@@ -46,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;
@@ -55,15 +81,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(new String[0]);
}
- } 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 276677f..7d288e7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -328,6 +328,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>