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

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

commit 71a23b4f4b9a5d257356e7b162ae1f8a6498c2c4
Author: Matt Sicker <[email protected]>
AuthorDate: Fri Nov 3 17:03:19 2023 -0500

    Clean up some warnings
    
    Signed-off-by: Matt Sicker <[email protected]>
---
 .../core/async/AsyncWaitStrategyFactoryConfig.java  | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncWaitStrategyFactoryConfig.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncWaitStrategyFactoryConfig.java
index 7d28b3507f..b6674ab9f8 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncWaitStrategyFactoryConfig.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncWaitStrategyFactoryConfig.java
@@ -19,13 +19,14 @@ package org.apache.logging.log4j.core.async;
 import java.util.Objects;
 
 import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.util.Loader;
 import org.apache.logging.log4j.plugins.Configurable;
 import org.apache.logging.log4j.plugins.Plugin;
 import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
 import org.apache.logging.log4j.plugins.PluginFactory;
 import org.apache.logging.log4j.plugins.validation.constraints.Required;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.Cast;
+import org.apache.logging.log4j.util.LoaderUtil;
 
 /**
  * This class allows users to configure the factory used to create
@@ -59,7 +60,7 @@ public class AsyncWaitStrategyFactoryConfig {
      *            The type to build
      */
     public static class Builder<B extends 
AsyncWaitStrategyFactoryConfig.Builder<B>>
-            implements 
org.apache.logging.log4j.core.util.Builder<AsyncWaitStrategyFactoryConfig> {
+            implements 
org.apache.logging.log4j.plugins.util.Builder<AsyncWaitStrategyFactoryConfig> {
 
         @PluginBuilderAttribute("class")
         @Required(message = "AsyncWaitStrategyFactory cannot be configured 
without a factory class name")
@@ -69,7 +70,7 @@ public class AsyncWaitStrategyFactoryConfig {
             return factoryClassName;
         }
 
-        public B withFactoryClassName(final String className) {
+        public B setFactoryClassName(final String className) {
             this.factoryClassName = className;
             return asBuilder();
         }
@@ -79,25 +80,17 @@ public class AsyncWaitStrategyFactoryConfig {
             return new AsyncWaitStrategyFactoryConfig(factoryClassName);
         }
 
-        @SuppressWarnings("unchecked")
         public B asBuilder() {
-            return (B) this;
+            return Cast.cast(this);
         }
     }
 
     public AsyncWaitStrategyFactory createWaitStrategyFactory() {
         try {
-            @SuppressWarnings("unchecked")
-            final Class<? extends AsyncWaitStrategyFactory> klass = (Class<? 
extends AsyncWaitStrategyFactory>) Loader.loadClass(factoryClassName);
-            if (AsyncWaitStrategyFactory.class.isAssignableFrom(klass)) {
-                return klass.newInstance();
-            }
-            LOGGER.error("Ignoring factory '{}': it is not assignable to 
AsyncWaitStrategyFactory", factoryClassName);
-            return null;
-        } catch (ClassNotFoundException | InstantiationException | 
IllegalAccessException e) {
+            return LoaderUtil.newCheckedInstanceOf(factoryClassName, 
AsyncWaitStrategyFactory.class);
+        } catch (ReflectiveOperationException | LinkageError e) {
             LOGGER.info("Invalid implementation class name value: error 
creating AsyncWaitStrategyFactory {}: {}", factoryClassName, e);
             return null;
         }
-
     }
 }

Reply via email to