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 2015/06/10 18:54:46 UTC

logging-log4j2 git commit: [LOG4J2-1017] Update Java platform from Java 6 to 7. Use Java 7 Throwable APIs.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 21f0aeff3 -> 9d8757e4f


[LOG4J2-1017] Update Java platform from Java 6 to 7. Use Java 7
Throwable APIs.

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

Branch: refs/heads/master
Commit: 9d8757e4f19ec6ccc2b7fe310705ae518c6d9a02
Parents: 21f0aef
Author: Gary Gregory <ga...@gmail.com>
Authored: Wed Jun 10 09:54:43 2015 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Wed Jun 10 09:54:43 2015 -0700

----------------------------------------------------------------------
 .../logging/log4j/core/impl/ThrowableProxy.java |  2 +-
 .../logging/log4j/core/util/Throwables.java     | 59 +++-----------------
 .../log4j/core/layout/JsonLayoutTest.java       |  5 +-
 .../log4j/core/layout/LogEventFixtures.java     |  4 +-
 .../log4j/core/layout/XmlLayoutTest.java        |  4 +-
 5 files changed, 13 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d8757e4/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 2e2c617..1ef7d25 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
@@ -612,7 +612,7 @@ public class ThrowableProxy implements Serializable {
 
     private ThrowableProxy[] toSuppressedProxies(final Throwable thrown, Set<Throwable> suppressedVisited) {
         try {
-            final Throwable[] suppressed = Throwables.getSuppressed(thrown);
+            final Throwable[] suppressed = thrown.getSuppressed();
             if (suppressed == null) {
                 return EMPTY_THROWABLE_PROXY_ARRAY;
             }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d8757e4/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java
index 2a64ac2..a852772 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java
@@ -22,37 +22,15 @@ import java.io.LineNumberReader;
 import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.logging.log4j.status.StatusLogger;
-
 /**
  * Helps with Throwable objects.
  */
 public final class Throwables {
 
-    private static final Method ADD_SUPPRESSED;
-
-    private static final Method GET_SUPPRESSED;
-
-    static {
-        Method getSuppressed = null, addSuppressed = null;
-        final Method[] methods = Throwable.class.getMethods();
-        for (final Method method : methods) {
-            if (method.getName().equals("getSuppressed")) {
-                getSuppressed = method;
-            } else if (method.getName().equals("addSuppressed")) {
-                addSuppressed = method;
-            }
-        }
-        GET_SUPPRESSED = getSuppressed;
-        ADD_SUPPRESSED = addSuppressed;
-    }
-
     /**
      * Has no effect on Java 6 and below.
      *
@@ -60,25 +38,11 @@ public final class Throwables {
      * @param suppressedThrowable a suppressed Throwable
      * @see Throwable#addSuppressed(Throwable)
      * @deprecated If compiling on Java 7 and above use {@link Throwable#addSuppressed(Throwable)}. Marked as deprecated because Java 6 is
-     *             deprecated.
+     *             deprecated. Will be removed in 2.5.
      */
     @Deprecated
     public static void addSuppressed(final Throwable throwable, final Throwable suppressedThrowable) {
-        if (ADD_SUPPRESSED != null) {
-            try {
-                ADD_SUPPRESSED.invoke(throwable, suppressedThrowable);
-            } catch (final IllegalAccessException e) {
-                // Only happens on Java >= 7 if this class has a bug.
-                StatusLogger.getLogger().error(e);
-            } catch (final IllegalArgumentException e) {
-                // Only happens on Java >= 7 if this class has a bug.
-                StatusLogger.getLogger().error(e);
-            } catch (final InvocationTargetException e) {
-                // Only happens on Java >= 7 if this class has a bug.
-                StatusLogger.getLogger().error(e);
-            }
-        }
-
+        throwable.addSuppressed(suppressedThrowable);
     }
 
     /**
@@ -88,29 +52,22 @@ public final class Throwables {
      * @return see Java 7's {@link Throwable#getSuppressed()}
      * @see Throwable#getSuppressed()
      * @deprecated If compiling on Java 7 and above use {@link Throwable#getSuppressed()}. Marked as deprecated because Java 6 is
-     *             deprecated.
+     *             deprecated. Will be removed 2.5.
      */
     @Deprecated
     public static Throwable[] getSuppressed(final Throwable throwable) {
-        if (GET_SUPPRESSED != null) {
-            try {
-                return (Throwable[]) GET_SUPPRESSED.invoke(throwable);
-            } catch (final Exception e) {
-                // Only happens on Java >= 7 if this class has a bug.
-                StatusLogger.getLogger().error(e);
-                return null;
-            }
-        }
-        return null;
+        return throwable.getSuppressed();
     }
 
     /**
      * Returns true if the getSuppressed method is available.
      * 
-     * @return True if getSuppressed is available.
+     * @return True if getSuppressed is available. As of 2.4, always returns true.
+     * @deprecated Will be removed in 2.5. As of 2.4, always returns true.
      */
+    @Deprecated
     public static boolean isGetSuppressedAvailable() {
-        return GET_SUPPRESSED != null;
+        return true;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d8757e4/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
index 64a419b..f8e67b2 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
@@ -34,7 +34,6 @@ import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
-import org.apache.logging.log4j.core.util.Throwables;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.spi.AbstractLogger;
 import org.apache.logging.log4j.test.appender.ListAppender;
@@ -145,9 +144,7 @@ public class JsonLayoutTest {
         this.checkPropertyName("commonElementCount", compact, str);
         this.checkPropertyName("localizedMessage", compact, str);
         this.checkPropertyName("extendedStackTrace", compact, str);
-        if (Throwables.isGetSuppressedAvailable()) {
-            this.checkPropertyName("suppressed", compact, str);
-        }
+        this.checkPropertyName("suppressed", compact, str);
         this.checkPropertyName("loggerFqcn", compact, str);
         this.checkPropertyName("endOfBatch", compact, str);
         if (includeContext) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d8757e4/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java
index f0e9b44..f96cdf3 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/LogEventFixtures.java
@@ -54,8 +54,8 @@ class LogEventFixtures {
         sourceHelper.fillInStackTrace();
         final StackTraceElement source = sourceHelper.getStackTrace()[0];
         final IOException ioException = new IOException("testIOEx", cause);
-        Throwables.addSuppressed(ioException, new IndexOutOfBoundsException("I am suppressed exception 1"));
-        Throwables.addSuppressed(ioException, new IndexOutOfBoundsException("I am suppressed exception 2"));
+        ioException.addSuppressed(new IndexOutOfBoundsException("I am suppressed exception 1"));
+        ioException.addSuppressed(new IndexOutOfBoundsException("I am suppressed exception 2"));
         final ThrowableProxy throwableProxy = new ThrowableProxy(ioException);
         final Map<String, String> contextMap = new HashMap<>();
         contextMap.put("MDC.A", "A_Value");

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9d8757e4/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java
index f6fe52d..42d995c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/XmlLayoutTest.java
@@ -167,9 +167,7 @@ public class XmlLayoutTest {
         this.checkAttributeName("message", compact, str);
         this.checkAttributeName("localizedMessage", compact, str);
         this.checkElementName("ExtendedStackTrace", compact, str, false, true);
-        if (Throwables.isGetSuppressedAvailable()) {
-            this.checkElementName("Suppressed", compact, str, false, true);
-        }
+        this.checkElementName("Suppressed", compact, str, false, true);
         this.checkAttributeName("loggerFqcn", compact, str);
         this.checkAttributeName("endOfBatch", compact, str);
         if (includeContext) {