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 2014/05/25 03:49:53 UTC

svn commit: r1597366 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java

Author: mattsicker
Date: Sun May 25 01:49:52 2014
New Revision: 1597366

URL: http://svn.apache.org/r1597366
Log:
Add type checking for Node and Configuration assignment.

  - This will help prevent runtime reflection exceptions when calling the plugin factory method. Instead, an error message is logged by StatusLogger.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java?rev=1597366&r1=1597365&r2=1597366&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilder.java Sun May 25 01:49:52 2014
@@ -172,15 +172,23 @@ public class PluginBuilder<T> {
                 }
                 sb.append(sb.length() == 0 ? "with params(" : ", ");
                 if (a instanceof PluginNode) {
-                    // TODO: type check against Node
-                    args[i] = node;
-                    sb.append("Node=").append(node.getName());
+                    if (types[i].isInstance(node)) {
+                        args[i] = node;
+                        sb.append("Node=").append(node.getName());
+                    } else {
+                        LOGGER.warn("Parameter annotated with PluginNode is not compatible with type {}.",
+                            node.getClass().getName());
+                    }
                 } else if (a instanceof PluginConfiguration) {
-                    // TODO: type check against Configuration
-                    args[i] = configuration;
-                    sb.append("Configuration");
-                    if (configuration.getName() != null) {
-                        sb.append('(').append(configuration.getName()).append(')');
+                    if (types[i].isInstance(configuration)) {
+                        args[i] = configuration;
+                        sb.append("Configuration");
+                        if (configuration.getName() != null) {
+                            sb.append('(').append(configuration.getName()).append(')');
+                        }
+                    } else {
+                        LOGGER.warn("Parameter annotated with PluginConfiguration is not compatible with type {}.",
+                            configuration.getClass().getName());
                     }
                 } else if (a instanceof PluginValue) {
                     final String name = ((PluginValue) a).value();