You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2015/08/09 17:29:37 UTC

logging-log4j2 git commit: LOG4J2-599 Log4j should not attempt to catch exceptions thrown by client code lambda expressions

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-599-LambdaSupport 12be6d867 -> 2d924ce7d


LOG4J2-599 Log4j should not attempt to catch exceptions thrown by client
code lambda expressions

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

Branch: refs/heads/LOG4J2-599-LambdaSupport
Commit: 2d924ce7d41ee2a53e940d7beef03cb28a993056
Parents: 12be6d8
Author: rpopma <rp...@apache.org>
Authored: Mon Aug 10 00:29:38 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Mon Aug 10 00:29:38 2015 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/util/LambdaUtil.java   |  8 +----
 .../logging/log4j/util/LambdaUtilTest.java      | 31 +++++++-------------
 2 files changed, 12 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d924ce7/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java
index 954886b..4a7479e 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/LambdaUtil.java
@@ -52,13 +52,7 @@ public class LambdaUtil {
         if (supplier == null) {
             return null;
         }
-        Object result = null;
-        try {
-            result = supplier.get();
-        } catch (Exception ex) {
-            result = ex;
-        }
-        return result;
+        return supplier.get();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d924ce7/log4j-api/src/test/java/org/apache/logging/log4j/util/LambdaUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/LambdaUtilTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/LambdaUtilTest.java
index 946c63c..a97ca28 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/util/LambdaUtilTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/LambdaUtilTest.java
@@ -62,26 +62,22 @@ public class LambdaUtilTest {
         assertNull(actual);
     }
 
-    @Test
+    @Test(expected = RuntimeException.class)
     public void testGetSupplierExceptionIfSupplierThrowsException() {
-        final RuntimeException expected = new RuntimeException();
-        final Object actual = LambdaUtil.get(new Supplier<String>() {
+        LambdaUtil.get(new Supplier<String>() {
             public String get() {
-                throw expected;
+                throw new RuntimeException();
             }
         });
-        assertSame(expected, actual);
     }
 
-    @Test
+    @Test(expected = RuntimeException.class)
     public void testGetMessageSupplierExceptionIfSupplierThrowsException() {
-        final RuntimeException expected = new RuntimeException();
-        final Object actual = LambdaUtil.get(new MessageSupplier() {
+        LambdaUtil.get(new MessageSupplier() {
             public Message get() {
-                throw expected;
+                throw new RuntimeException();
             }
         });
-        assertSame(expected, actual);
     }
 
     @Test
@@ -122,25 +118,20 @@ public class LambdaUtilTest {
         }
     }
 
-    @Test
-    public void testGetAllReturnsExceptionsIfSuppliersThrowsException() {
-        final RuntimeException expected1 = new RuntimeException();
+    @Test(expected = RuntimeException.class)
+    public void testGetAllThrowsExceptionIfAnyOfTheSuppliersThrowsException() {
         Supplier<String> function1 = new Supplier<String>() {
             public String get() {
-                throw expected1;
+                return "abc";
             }
         };
-        final RuntimeException expected2 = new RuntimeException();
         Supplier<String> function2 = new Supplier<String>() {
             public String get() {
-                throw expected2;
+                throw new RuntimeException();
             }
         };
 
         Supplier<?>[] functions = { function1, function2 };
-        final Object[] actual = LambdaUtil.getAll(functions);
-        assertEquals(actual.length, functions.length);
-        assertSame(expected1, actual[0]);
-        assertSame(expected2, actual[1]);
+        LambdaUtil.getAll(functions);
     }
 }