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 21:16:14 UTC
[logging-log4j2] branch release-2.x updated: Update for Carter's comments.
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 e4bdbab Update for Carter's comments.
e4bdbab is described below
commit e4bdbabb8286044cac8a220ca473c8b9702908f0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 5 16:16:10 2022 -0500
Update for Carter's comments.
---
.../org/apache/log4j/spi/ThrowableInformation.java | 29 ++++++++++++----------
1 file changed, 16 insertions(+), 13 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 b61b17d..2b46dd5 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,6 +16,7 @@
*/
package org.apache.log4j.spi;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.List;
@@ -25,14 +26,25 @@ import org.apache.logging.log4j.util.Strings;
/**
* Log4j's internal representation of throwables.
*/
-public class ThrowableInformation implements java.io.Serializable {
+public class ThrowableInformation implements Serializable {
static final long serialVersionUID = -4748765566864322735L;
private transient Throwable throwable;
private transient Category category;
private String[] rep;
- private Method toStringList;
+ private static final Method TO_STRING_LIST;
+
+ static {
+ Method method = null;
+ try {
+ 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.
+ }
+ TO_STRING_LIST = method;
+ }
/**
* Constructs new instance.
@@ -49,14 +61,6 @@ public class ThrowableInformation implements java.io.Serializable {
*/
public ThrowableInformation(final Throwable throwable) {
this.throwable = throwable;
- Method method = null;
- try {
- 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.
- }
- this.toStringList = method;
}
/**
@@ -77,11 +81,10 @@ public class ThrowableInformation implements java.io.Serializable {
}
public synchronized String[] getThrowableStrRep() {
- if (toStringList != null && throwable != null) {
+ if (TO_STRING_LIST != null && throwable != null) {
try {
@SuppressWarnings("unchecked")
- final
- List<String> elements = (List<String>) toStringList.invoke(null, throwable);
+ final List<String> elements = (List<String>) TO_STRING_LIST.invoke(null, throwable);
if (elements != null) {
return elements.toArray(Strings.EMPTY_ARRAY);
}