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 2021/01/08 16:18:51 UTC

[logging-log4j2] branch master updated: Collapse multiple identical catch clauses into one.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new be8d827  Collapse multiple identical catch clauses into one.
be8d827 is described below

commit be8d827bb25760b653b9c2c968665f05d35bfbc2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jan 8 11:18:44 2021 -0500

    Collapse multiple identical catch clauses into one.
---
 .../org/apache/logging/log4j/core/lookup/Interpolator.java  |  4 +---
 .../log4j/core/pattern/AbstractStyleNameConverter.java      | 13 ++-----------
 .../logging/log4j/core/net/ssl/SslConfigurationTest.java    | 11 ++++-------
 .../logging/log4j/plugins/processor/PluginProcessor.java    |  4 ----
 4 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
index 446d57b..cea22d6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
@@ -150,9 +150,7 @@ public class Interpolator extends AbstractConfigurationAwareLookup {
         try {
             strLookupMap.put(LOOKUP_KEY_KUBERNETES,
                     Loader.newCheckedInstanceOf("org.apache.logging.log4j.kubernetes.KubernetesLookup", StrLookup.class));
-        } catch (final Exception ignored) {
-            handleError(LOOKUP_KEY_KUBERNETES, ignored);
-        } catch (final NoClassDefFoundError error) {
+        } catch (final Exception | NoClassDefFoundError error) {
             handleError(LOOKUP_KEY_KUBERNETES, error);
         }
     }
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java
index a82aa1f..f3e869f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/AbstractStyleNameConverter.java
@@ -331,17 +331,8 @@ public abstract class AbstractStyleNameConverter extends LogEventPatternConverte
         try {
             final Constructor<T> constructor = asnConverterClass.getConstructor(List.class, String.class);
             return constructor.newInstance(formatters, AnsiEscape.createSequence(name));
-        } catch (final SecurityException e) {
-            LOGGER.error(e.toString(), e);
-        } catch (final NoSuchMethodException e) {
-            LOGGER.error(e.toString(), e);
-        } catch (final IllegalArgumentException e) {
-            LOGGER.error(e.toString(), e);
-        } catch (final InstantiationException e) {
-            LOGGER.error(e.toString(), e);
-        } catch (final IllegalAccessException e) {
-            LOGGER.error(e.toString(), e);
-        } catch (final InvocationTargetException e) {
+        } catch (final SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException
+                | IllegalAccessException | InvocationTargetException e) {
             LOGGER.error(e.toString(), e);
         }
         return null;
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
index fa0a35f..7b62845 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationTest.java
@@ -87,7 +87,8 @@ public class SslConfigurationTest {
 
     @Test
     public void equals() {
-        assertEquals(SslConfiguration.createSSLConfiguration(null, null, null), SslConfiguration.createSSLConfiguration(null, null, null));
+        assertEquals(SslConfiguration.createSSLConfiguration(null, null, null),
+                SslConfiguration.createSSLConfiguration(null, null, null));
     }
 
     @Test
@@ -105,9 +106,7 @@ public class SslConfigurationTest {
             try (final SSLSocket clientSocket = (SSLSocket) factory.createSocket(TLS_TEST_HOST, TLS_TEST_PORT)) {
                 assertNotNull(clientSocket);
             }
-        } catch (final UnknownHostException offline) {
-            // this exception is thrown on Windows when offline
-        } catch (final ConnectException connectionTimeout) {
+        } catch (final UnknownHostException | ConnectException connectionTimeout) {
             // this exception is thrown on Windows when host is behind a proxy that does not allow connection to external network
         }
     }
@@ -124,9 +123,7 @@ public class SslConfigurationTest {
                     assertThrows(IOException.class, () -> os.write("GET config/login_verify2?".getBytes()));
                 }
             }
-        } catch (final UnknownHostException offline) {
-            // this exception is thrown on Windows when offline
-        } catch (final ConnectException connectionTimeout) {
+        } catch (final UnknownHostException | ConnectException connectionTimeout) {
             // this exception is thrown on Windows when host is behind a proxy that does not allow connection to external network
         }
     }
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/processor/PluginProcessor.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/processor/PluginProcessor.java
index 6ccfdd2..d655416 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/processor/PluginProcessor.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/processor/PluginProcessor.java
@@ -92,10 +92,6 @@ public class PluginProcessor extends AbstractProcessor {
             writeServiceFile(packageName);
             messager.printMessage(Kind.NOTE, "Annotations processed");
             return true;
-        } catch (final IOException e) {
-            e.printStackTrace();
-            error(e.getMessage());
-            return false;
         } catch (final Exception ex) {
             ex.printStackTrace();
             error(ex.getMessage());