You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2019/10/07 02:10:02 UTC

[logging-log4j2] 02/03: Simplify exception handling

This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 4615978dcc70fc8e64b004a4cd90a1132a3931c2
Author: Matt Sicker <bo...@gmail.com>
AuthorDate: Sun Oct 6 21:07:17 2019 -0500

    Simplify exception handling
    
    Signed-off-by: Matt Sicker <bo...@gmail.com>
---
 .../log4j/core/config/plugins/util/PluginBuilder.java  | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java
index 51f9c3e..5fa120d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java
@@ -20,7 +20,6 @@ package org.apache.logging.log4j.core.config.plugins.util;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.plugins.Node;
 import org.apache.logging.log4j.plugins.PluginAliases;
@@ -117,21 +116,24 @@ public class PluginBuilder implements Builder<Object> {
     @Override
     public Object build() {
         verify();
+        LOGGER.debug("Building Plugin[name={}, class={}].", pluginType.getElementName(),
+                pluginType.getPluginClass().getName());
         substitutor = new Substitutor(event);
         // first try to use a builder class if one is available
         try {
-            LOGGER.debug("Building Plugin[name={}, class={}].", pluginType.getElementName(),
-                    pluginType.getPluginClass().getName());
             final Builder<?> builder = createBuilder(this.clazz);
             if (builder != null) {
                 return injectBuilder(builder);
             }
-        } catch (final ConfigurationException e) { // LOG4J2-1908
-            LOGGER.error("Could not create plugin of type {} for element {}", this.clazz, node.getName(), e);
+        } catch (final InvocationTargetException e) {
+            LOGGER.error("Could not create plugin builder for plugin {} and element {}", clazz, node.getName(), e.getCause());
+            return null;
+        } catch (final IllegalAccessException e) {
+            LOGGER.error("Could not access plugin builder for plugin {} and element {}", clazz, node.getName());
+            return null;
+        } catch (final RuntimeException e) { // LOG4J2-1908
+            LOGGER.error("Could not create plugin of type {} for element {}", clazz, node.getName(), e);
             return null; // no point in trying the factory method
-        } catch (final Exception e) {
-            LOGGER.error("Could not create plugin of type {} for element {}: {}", clazz, node.getName(),
-                    e.toString(), e);
         }
         // or fall back to factory method if no builder class is available
         try {